From b807a7bb96a2ad57f684bcb4cbc043ea301565f9 Mon Sep 17 00:00:00 2001 From: Ahmed Darrazi Date: Mon, 19 Jan 2026 21:21:02 +0100 Subject: [PATCH] fix(queue): handle legacy bulk restore job payloads --- app/Jobs/BulkBackupSetRestoreJob.php | 51 ++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/app/Jobs/BulkBackupSetRestoreJob.php b/app/Jobs/BulkBackupSetRestoreJob.php index fcaa47d..ceb34c2 100644 --- a/app/Jobs/BulkBackupSetRestoreJob.php +++ b/app/Jobs/BulkBackupSetRestoreJob.php @@ -11,11 +11,14 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; use RuntimeException; +use Throwable; class BulkBackupSetRestoreJob implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; + public int $bulkRunId = 0; + public ?OperationRun $operationRun = null; /** @@ -30,13 +33,12 @@ public function __construct( public array $context = [], ) { $this->operationRun = $operationRun; + $this->bulkRunId = $operationRun?->getKey() ? (int) $operationRun->getKey() : 0; } public function handle(OperationRunService $runs): void { - if (! $this->operationRun instanceof OperationRun) { - throw new RuntimeException('OperationRun is required for BulkBackupSetRestoreJob.'); - } + $this->operationRun = $this->resolveOperationRun(); $this->operationRun->refresh(); @@ -66,6 +68,49 @@ public function handle(OperationRunService $runs): void } } + public function failed(Throwable $e): void + { + $run = $this->operationRun; + + if (! $run instanceof OperationRun && $this->bulkRunId > 0) { + $run = OperationRun::query()->find($this->bulkRunId); + } + + if (! $run instanceof OperationRun) { + return; + } + + /** @var OperationRunService $runs */ + $runs = app(OperationRunService::class); + + $runs->updateRun( + $run, + status: 'completed', + outcome: 'failed', + failures: [[ + 'code' => 'bulk_job.failed', + 'message' => $e->getMessage(), + ]], + ); + } + + private function resolveOperationRun(): OperationRun + { + if ($this->operationRun instanceof OperationRun) { + return $this->operationRun; + } + + if ($this->bulkRunId > 0) { + $run = OperationRun::query()->find($this->bulkRunId); + + if ($run instanceof OperationRun) { + return $run; + } + } + + throw new RuntimeException('OperationRun is required for BulkBackupSetRestoreJob.'); + } + /** * @param array $ids * @return array