Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
fix: fix batch of scheduled reminders (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Jan 12, 2023
1 parent 0e03e7e commit 74d3218
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/Console/Commands/TestReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ public function handle(): void
}

try {
(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $scheduledReminder->contact_reminder_id,
'user_notification_channel_id' => $scheduledReminder->user_notification_channel_id,
'contact_reminder_scheduled_id' => $scheduledReminder->id,
]))->handle();
]);
} catch (ModelNotFoundException) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,16 @@ public function handle()

$this->updateScheduledContactReminderTriggeredAt($scheduledReminder);
$this->updateNumberOfTimesTriggered($scheduledReminder->contact_reminder_id);

$this->appendToChain(
new RescheduleContactReminderForChannel([
'contact_reminder_id' => $scheduledReminder->contact_reminder_id,
'user_notification_channel_id' => $scheduledReminder->user_notification_channel_id,
'contact_reminder_scheduled_id' => $scheduledReminder->id,
])
);
}
}

private function updateScheduledContactReminderTriggeredAt($scheduledReminder): void
{
(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $scheduledReminder->contact_reminder_id,
'user_notification_channel_id' => $scheduledReminder->user_notification_channel_id,
'contact_reminder_scheduled_id' => $scheduledReminder->id,
]))->handle();
]);
}

private function updateNumberOfTimesTriggered(int $id): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
use App\Interfaces\ServiceInterface;
use App\Models\ContactReminder;
use App\Models\UserNotificationChannel;
use App\Services\QueuableService;
use App\Services\BaseService;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\DB;

class RescheduleContactReminderForChannel extends QueuableService implements ServiceInterface
class RescheduleContactReminderForChannel extends BaseService implements ServiceInterface
{
private UserNotificationChannel $userNotificationChannel;

private ContactReminder $contactReminder;

private Carbon $upcomingDate;

private array $data;

/**
* Get the validation rules that apply to the service.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public function it_doesnt_schedules_a_one_time_contact_reminder_again(): void
'scheduled_at' => '2018-01-01 00:00:00',
]);

(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $contactReminder->id,
'user_notification_channel_id' => $channel->id,
'contact_reminder_scheduled_id' => $id,
]))->handle();
]);

$this->assertDatabaseMissing('contact_reminder_scheduled', [
'user_notification_channel_id' => $channel->id,
Expand Down Expand Up @@ -72,11 +72,11 @@ public function it_schedules_a_daily_contact_reminder_again(): void
'scheduled_at' => '2018-01-01 00:00:00',
]);

(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $contactReminder->id,
'user_notification_channel_id' => $channel->id,
'contact_reminder_scheduled_id' => $id,
]))->handle();
]);

$this->assertDatabaseHas('contact_reminder_scheduled', [
'user_notification_channel_id' => $channel->id,
Expand Down Expand Up @@ -107,11 +107,11 @@ public function it_schedules_a_monthly_contact_reminder_again(): void
'scheduled_at' => '2018-01-01 00:00:00',
]);

(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $contactReminder->id,
'user_notification_channel_id' => $channel->id,
'contact_reminder_scheduled_id' => $id,
]))->handle();
]);

$this->assertDatabaseHas('contact_reminder_scheduled', [
'user_notification_channel_id' => $channel->id,
Expand Down Expand Up @@ -142,11 +142,11 @@ public function it_schedules_a_yearly_contact_reminder_again(): void
'scheduled_at' => '2018-01-01 00:00:00',
]);

(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $contactReminder->id,
'user_notification_channel_id' => $channel->id,
'contact_reminder_scheduled_id' => $id,
]))->handle();
]);

$this->assertDatabaseHas('contact_reminder_scheduled', [
'user_notification_channel_id' => $channel->id,
Expand Down Expand Up @@ -180,11 +180,11 @@ public function it_doesnt_schedules_a_yearly_contact_reminder_again_if_channel_i
'scheduled_at' => '2018-01-01 00:00:00',
]);

(new RescheduleContactReminderForChannel([
(new RescheduleContactReminderForChannel())->execute([
'contact_reminder_id' => $contactReminder->id,
'user_notification_channel_id' => $channel->id,
'contact_reminder_scheduled_id' => $id,
]))->handle();
]);

$this->assertDatabaseMissing('contact_reminder_scheduled', [
'user_notification_channel_id' => $channel->id,
Expand Down

0 comments on commit 74d3218

Please sign in to comment.