find($this->restoreRunId); if (! $restoreRun) { return; } if ($restoreRun->status !== RestoreRunStatus::Queued->value) { return; } $tenant = $restoreRun->tenant; $backupSet = $restoreRun->backupSet; if (! $tenant || ! $backupSet || $backupSet->trashed()) { $restoreRun->update([ 'status' => RestoreRunStatus::Failed->value, 'failure_reason' => 'Backup set is archived or unavailable.', 'completed_at' => CarbonImmutable::now(), ]); if ($tenant) { $auditLogger->log( tenant: $tenant, action: 'restore.failed', context: [ 'metadata' => [ 'restore_run_id' => $restoreRun->id, 'backup_set_id' => $restoreRun->backup_set_id, 'reason' => 'Backup set is archived or unavailable.', ], ], actorEmail: $this->actorEmail, actorName: $this->actorName, resourceType: 'restore_run', resourceId: (string) $restoreRun->id, status: 'failed', ); } return; } $restoreRun->update([ 'status' => RestoreRunStatus::Running->value, 'started_at' => CarbonImmutable::now(), 'failure_reason' => null, ]); $auditLogger->log( tenant: $tenant, action: 'restore.started', context: [ 'metadata' => [ 'restore_run_id' => $restoreRun->id, 'backup_set_id' => $backupSet->id, ], ], actorEmail: $this->actorEmail, actorName: $this->actorName, resourceType: 'restore_run', resourceId: (string) $restoreRun->id, status: 'success', ); try { $restoreService->executeForRun( restoreRun: $restoreRun, tenant: $tenant, backupSet: $backupSet, actorEmail: $this->actorEmail, actorName: $this->actorName, ); } catch (Throwable $throwable) { $restoreRun->refresh(); if ($restoreRun->status === RestoreRunStatus::Running->value) { $restoreRun->update([ 'status' => RestoreRunStatus::Failed->value, 'failure_reason' => $throwable->getMessage(), 'completed_at' => CarbonImmutable::now(), ]); } if ($tenant) { $auditLogger->log( tenant: $tenant, action: 'restore.failed', context: [ 'metadata' => [ 'restore_run_id' => $restoreRun->id, 'backup_set_id' => $backupSet->id, 'reason' => $throwable->getMessage(), ], ], actorEmail: $this->actorEmail, actorName: $this->actorName, resourceType: 'restore_run', resourceId: (string) $restoreRun->id, status: 'failed', ); } throw $throwable; } } }