fix(queue): handle legacy bulk restore job payloads
This commit is contained in:
parent
cb3da561ef
commit
b807a7bb96
@ -11,11 +11,14 @@
|
|||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class BulkBackupSetRestoreJob implements ShouldQueue
|
class BulkBackupSetRestoreJob implements ShouldQueue
|
||||||
{
|
{
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public int $bulkRunId = 0;
|
||||||
|
|
||||||
public ?OperationRun $operationRun = null;
|
public ?OperationRun $operationRun = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,13 +33,12 @@ public function __construct(
|
|||||||
public array $context = [],
|
public array $context = [],
|
||||||
) {
|
) {
|
||||||
$this->operationRun = $operationRun;
|
$this->operationRun = $operationRun;
|
||||||
|
$this->bulkRunId = $operationRun?->getKey() ? (int) $operationRun->getKey() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle(OperationRunService $runs): void
|
public function handle(OperationRunService $runs): void
|
||||||
{
|
{
|
||||||
if (! $this->operationRun instanceof OperationRun) {
|
$this->operationRun = $this->resolveOperationRun();
|
||||||
throw new RuntimeException('OperationRun is required for BulkBackupSetRestoreJob.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->operationRun->refresh();
|
$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<int, mixed> $ids
|
* @param array<int, mixed> $ids
|
||||||
* @return array<int, int>
|
* @return array<int, int>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user