| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Jobs;
- use App\Services\OrderPaymentStatusService;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Foundation\Queue\Queueable;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Log;
- class BackfillPaidOrderStatusesJob implements ShouldQueue
- {
- use Queueable;
- public int $timeout = 1200;
- public int $tries = 1;
- public function __construct(
- private readonly ?int $year = null,
- private readonly int $chunkSize = 500,
- ) {
- }
- public function handle(OrderPaymentStatusService $paymentStatusService): void
- {
- $checked = 0;
- $markedPaid = 0;
- $paymentStatusService
- ->paidBackfillCandidatesQuery($this->year)
- ->select('orders.id')
- ->chunkById($this->chunkSize, function (Collection $orders) use ($paymentStatusService, &$checked, &$markedPaid): void {
- foreach ($orders as $order) {
- $checked++;
- if ($paymentStatusService->markPaidIfAllMafsHavePaymentData((int) $order->id)) {
- $markedPaid++;
- }
- }
- }, 'orders.id', 'id');
- Log::info('Paid order statuses backfill finished.', [
- 'year' => $this->year,
- 'checked' => $checked,
- 'marked_paid' => $markedPaid,
- ]);
- }
- }
|