## Summary - harden operation-run lifecycle handling with explicit reconciliation policy, stale-run healing, failed-job bridging, and monitoring visibility - refactor audit log event inspection into a Filament slide-over and remove the stale inline detail/header-action coupling - align panel theme asset resolution and supporting Filament UI updates, including the rounded 2xl theme token regression fix ## Testing - ran focused Pest coverage for the affected audit-log inspection flow and related visibility tests - ran formatting with `vendor/bin/sail bin pint --dirty --format agent` - manually verified the updated audit-log slide-over flow in the integrated browser ## Notes - branch includes the Spec 160 artifacts under `specs/160-operation-lifecycle-guarantees/` - the full test suite was not rerun as part of this final commit/PR step Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #190
148 lines
4.5 KiB
PHP
148 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\BackupSchedule;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Services\OperationRunService;
|
|
use App\Services\Operations\OperationLifecycleReconciler;
|
|
use App\Support\OperationRunOutcome;
|
|
use Illuminate\Console\Command;
|
|
|
|
class TenantpilotReconcileBackupScheduleOperationRuns extends Command
|
|
{
|
|
protected $signature = 'tenantpilot:operation-runs:reconcile-backup-schedules
|
|
{--tenant=* : Limit to tenant_id/external_id}
|
|
{--older-than=5 : Only reconcile runs older than N minutes}
|
|
{--dry-run : Do not write changes}';
|
|
|
|
protected $description = 'Reconcile stuck backup schedule OperationRuns without legacy run-table lookups.';
|
|
|
|
public function handle(
|
|
OperationRunService $operationRunService,
|
|
OperationLifecycleReconciler $operationLifecycleReconciler,
|
|
): int {
|
|
$tenantIdentifiers = array_values(array_filter((array) $this->option('tenant')));
|
|
$olderThanMinutes = max(0, (int) $this->option('older-than'));
|
|
$dryRun = (bool) $this->option('dry-run');
|
|
|
|
$query = OperationRun::query()
|
|
->where('type', 'backup_schedule_run')
|
|
->whereIn('status', ['queued', 'running']);
|
|
|
|
if ($olderThanMinutes > 0) {
|
|
$query->where('created_at', '<', now()->subMinutes($olderThanMinutes));
|
|
}
|
|
|
|
if ($tenantIdentifiers !== []) {
|
|
$tenantIds = $this->resolveTenantIds($tenantIdentifiers);
|
|
|
|
if ($tenantIds === []) {
|
|
$this->info('No tenants matched the provided identifiers.');
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$query->whereIn('tenant_id', $tenantIds);
|
|
}
|
|
|
|
$reconciled = 0;
|
|
$skipped = 0;
|
|
$failed = 0;
|
|
|
|
foreach ($query->cursor() as $operationRun) {
|
|
$backupScheduleId = data_get($operationRun->context, 'backup_schedule_id');
|
|
|
|
if (! is_numeric($backupScheduleId)) {
|
|
if (! $dryRun) {
|
|
$operationRunService->updateRun(
|
|
$operationRun,
|
|
status: 'completed',
|
|
outcome: OperationRunOutcome::Failed->value,
|
|
failures: [
|
|
[
|
|
'code' => 'backup_schedule.missing_context',
|
|
'message' => 'Backup schedule context is missing from this operation run.',
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
$failed++;
|
|
|
|
continue;
|
|
}
|
|
|
|
$schedule = BackupSchedule::query()
|
|
->whereKey((int) $backupScheduleId)
|
|
->where('tenant_id', (int) $operationRun->tenant_id)
|
|
->first();
|
|
|
|
if (! $schedule instanceof BackupSchedule) {
|
|
if (! $dryRun) {
|
|
$operationRunService->updateRun(
|
|
$operationRun,
|
|
status: 'completed',
|
|
outcome: OperationRunOutcome::Failed->value,
|
|
failures: [
|
|
[
|
|
'code' => 'backup_schedule.not_found',
|
|
'message' => 'Backup schedule not found for this operation run.',
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
$failed++;
|
|
|
|
continue;
|
|
}
|
|
|
|
$change = $operationLifecycleReconciler->reconcileRun($operationRun, $dryRun);
|
|
|
|
if ($change !== null) {
|
|
$reconciled++;
|
|
|
|
continue;
|
|
}
|
|
|
|
$skipped++;
|
|
}
|
|
|
|
$this->info(sprintf(
|
|
'Reconciled %d run(s), skipped %d, failed %d.',
|
|
$reconciled,
|
|
$skipped,
|
|
$failed,
|
|
));
|
|
|
|
if ($dryRun) {
|
|
$this->comment('Dry-run: no changes written.');
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
/**
|
|
* @param array<int, string> $tenantIdentifiers
|
|
* @return array<int>
|
|
*/
|
|
private function resolveTenantIds(array $tenantIdentifiers): array
|
|
{
|
|
$tenantIds = [];
|
|
|
|
foreach ($tenantIdentifiers as $identifier) {
|
|
$tenant = Tenant::query()
|
|
->forTenant($identifier)
|
|
->first();
|
|
|
|
if ($tenant) {
|
|
$tenantIds[] = (int) $tenant->getKey();
|
|
}
|
|
}
|
|
|
|
return array_values(array_unique($tenantIds));
|
|
}
|
|
}
|