giftcon_dev/app/Jobs/Payments/ArchivePaymentsJob.php

53 lines
1.5 KiB
PHP

<?php
namespace App\Jobs\Payments;
use App\Services\Payments\PaymentArchiveService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
final class ArchivePaymentsJob implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $timeout = 120;
public int $tries = 1;
// 5분 동안 중복 실행 방지(스케줄러가 여러번 던져도 1개만)
public int $uniqueFor = 300;
public function __construct(
public int $days = 7,
public int $timeoutMin = 15,
public int $timeoutArchiveMin = 60,
public int $batch = 500,
) {}
public function uniqueId(): string
{
return 'payments-archive';
}
public function handle(PaymentArchiveService $svc): void
{
$batchId = substr(bin2hex(random_bytes(8)), 0, 16);
Log::info('[ArchivePaymentsJob] start', [
'batch' => $batchId,
'days' => $this->days,
'timeoutMin' => $this->timeoutMin,
'timeoutArchiveMin' => $this->timeoutArchiveMin,
'batchSize' => $this->batch,
]);
$result = $svc->run($this->days, $this->timeoutMin, $this->timeoutArchiveMin, $this->batch, $batchId);
Log::info('[ArchivePaymentsJob] end', ['batch' => $batchId] + $result);
}
}