ldc-cocotte/app/Jobs/UpsertShopsPickupExceptionsUsingApiForYear.php

51 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace App\Jobs;
use App\Contracts\Executor;
use App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsForYear;
use App\Cqs\Actions\PickupExceptions\UpsertShopsPickupExceptionsForYearInput;
use App\Services\PublicHolidaysApiService;
2026-06-14 21:32:07 +02:00
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Date;
class UpsertShopsPickupExceptionsUsingApiForYear implements ShouldQueue
{
use Queueable;
public int $tries = 3;
/**
* @var list<int>
*/
public array $backoff = [10, 30];
2026-06-14 21:32:07 +02:00
protected int $year;
public function __construct(?int $year = null)
{
$this->year = $year ?? Date::now()->addYear()->year;
throw_if(
$this->year < 2026,
\InvalidArgumentException::class
);
}
public function handle(
Executor $executor,
PublicHolidaysApiService $apiService,
UpsertShopsPickupExceptionsForYear $action,
): void {
$holidays = $apiService->fetchForYear($this->year);
$executor->execute(
$action,
new UpsertShopsPickupExceptionsForYearInput($this->year, $holidays),
2026-06-14 21:32:07 +02:00
);
}
}