ldc-cocotte/app/Jobs/UpsertShopsPickupExceptionsUsingApiForYear.php
Jérémy Munsch faef51091e
feat(pickup-exceptions): implement upsert and query for public holidays
Added functionality to upsert pickup exceptions for public holidays
and query for auto-updated exceptions. This includes new classes
for handling input and service integration with the public holidays API.
2026-11-15 20:04:29 +01:00

50 lines
1.2 KiB
PHP

<?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;
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];
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),
);
}
}