feat(jobs): implement unique job handling for reminders
Added ShouldBeUnique interface to SendMissingOrderReminderJob and SendReminderMail for unique job processing.
This commit is contained in:
parent
86e7340c48
commit
efbd507ac9
2 changed files with 20 additions and 2 deletions
|
|
@ -15,14 +15,16 @@ use Domain\Enums\OrderStatus;
|
|||
use Domain\Models\ValueObjects\IcsContent;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Domain\Services\PickupSchedulingService;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class SendMissingOrderReminderJob implements ShouldQueue
|
||||
class SendMissingOrderReminderJob implements ShouldBeUnique, ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
|
|
@ -30,6 +32,13 @@ class SendMissingOrderReminderJob implements ShouldQueue
|
|||
|
||||
public const int HOURS_BEFORE_CUTOFF = 6;
|
||||
|
||||
public int $uniqueFor = 3600;
|
||||
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return Date::now()->format('o-\WW');
|
||||
}
|
||||
|
||||
public function handle(PickupSchedulingService $schedulingService, IcsGeneratorService $icsGenerator): void
|
||||
{
|
||||
$pickupDay = Carbon::now()->next($schedulingService->getPickupDay()->value);
|
||||
|
|
|
|||
|
|
@ -11,19 +11,28 @@ use App\Models\Order;
|
|||
use App\Notifications\OrderTodayReminderNotification;
|
||||
use Domain\Enums\OrderStatus;
|
||||
use Domain\Models\ValueObjects\Matricule;
|
||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Queue\Queueable;
|
||||
use Illuminate\Support\Facades\Date;
|
||||
use Money\MoneyFormatter;
|
||||
|
||||
class SendReminderMail implements ShouldQueue
|
||||
class SendReminderMail implements ShouldBeUnique, ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public int $uniqueFor = 3600;
|
||||
|
||||
public function __construct(
|
||||
private readonly MoneyFormatter $moneyFormatter
|
||||
) {
|
||||
}
|
||||
|
||||
public function uniqueId(): string
|
||||
{
|
||||
return Date::now()->format('Y-m-d');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$orders = Order::query()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue