## 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
128 lines
4.1 KiB
PHP
128 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Jobs\Middleware\TrackOperationRun;
|
|
use App\Models\OperationRun;
|
|
use App\Models\Tenant;
|
|
use App\Services\Directory\RoleDefinitionsSyncService;
|
|
use App\Services\Intune\AuditLogger;
|
|
use App\Services\OperationRunService;
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use RuntimeException;
|
|
|
|
class SyncRoleDefinitionsJob implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public int $timeout = 240;
|
|
|
|
public bool $failOnTimeout = true;
|
|
|
|
public ?OperationRun $operationRun = null;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*/
|
|
public function __construct(
|
|
public int $tenantId,
|
|
?OperationRun $operationRun = null,
|
|
) {
|
|
$this->operationRun = $operationRun;
|
|
}
|
|
|
|
public function middleware(): array
|
|
{
|
|
return [new TrackOperationRun];
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(RoleDefinitionsSyncService $syncService, AuditLogger $auditLogger): void
|
|
{
|
|
if (! $this->operationRun) {
|
|
$this->fail(new RuntimeException('OperationRun context is required for SyncRoleDefinitionsJob.'));
|
|
|
|
return;
|
|
}
|
|
|
|
$tenant = Tenant::query()->find($this->tenantId);
|
|
if (! $tenant instanceof Tenant) {
|
|
throw new RuntimeException('Tenant not found.');
|
|
}
|
|
|
|
$auditLogger->log(
|
|
tenant: $tenant,
|
|
action: 'directory_role_definitions.sync.started',
|
|
context: [
|
|
'tenant_id' => (int) $tenant->getKey(),
|
|
],
|
|
actorId: $this->operationRun->user_id,
|
|
status: 'success',
|
|
resourceType: 'operation_run',
|
|
resourceId: (string) $this->operationRun->getKey(),
|
|
);
|
|
|
|
$result = $syncService->sync($tenant);
|
|
|
|
/** @var OperationRunService $opService */
|
|
$opService = app(OperationRunService::class);
|
|
|
|
$outcome = 'succeeded';
|
|
|
|
if ($result['error_code'] !== null) {
|
|
$outcome = 'failed';
|
|
} elseif ($result['safety_stop_triggered'] === true) {
|
|
$outcome = 'partially_succeeded';
|
|
}
|
|
|
|
$failures = [];
|
|
if (is_string($result['error_code']) && $result['error_code'] !== '') {
|
|
$failures[] = [
|
|
'code' => $result['error_code'],
|
|
'message' => is_string($result['error_summary']) ? $result['error_summary'] : 'Role definitions sync failed.',
|
|
];
|
|
}
|
|
|
|
$opService->updateRun(
|
|
$this->operationRun,
|
|
'completed',
|
|
$outcome,
|
|
[
|
|
'total' => $result['items_observed_count'],
|
|
'processed' => $result['items_observed_count'],
|
|
'updated' => $result['items_upserted_count'],
|
|
'failed' => $result['error_count'],
|
|
],
|
|
$failures,
|
|
);
|
|
|
|
$auditLogger->log(
|
|
tenant: $tenant,
|
|
action: $outcome === 'succeeded'
|
|
? 'directory_role_definitions.sync.succeeded'
|
|
: ($outcome === 'partially_succeeded'
|
|
? 'directory_role_definitions.sync.partial'
|
|
: 'directory_role_definitions.sync.failed'),
|
|
context: [
|
|
'pages_fetched' => $result['pages_fetched'],
|
|
'items_observed_count' => $result['items_observed_count'],
|
|
'items_upserted_count' => $result['items_upserted_count'],
|
|
'error_code' => $result['error_code'],
|
|
'error_category' => $result['error_category'],
|
|
'finished_at' => CarbonImmutable::now('UTC')->toIso8601String(),
|
|
],
|
|
actorId: $this->operationRun->user_id,
|
|
status: $outcome === 'failed' ? 'failed' : 'success',
|
|
resourceType: 'operation_run',
|
|
resourceId: (string) $this->operationRun->getKey(),
|
|
);
|
|
}
|
|
}
|