true, 'connection' => (string) config('queue.default'), 'snapshotLabel' => __('admin.ops_health.snapshot_missing'), 'queues' => [], 'alerts' => [], 'alertCount' => 0, 'stalledAssets' => 0, 'stalledMinutes' => $stalledMinutes, ]; } $queues = collect($snapshot['queues'] ?? []) ->map(fn (array $queue) => $this->formatQueue($queue)) ->values() ->all(); $alerts = collect($snapshot['alerts'] ?? []) ->map(fn (array $alert) => $this->formatAlert($alert)) ->values() ->all(); $snapshotAge = $this->formatSnapshotAge($snapshot['generated_at'] ?? null); $snapshotLabel = $snapshotAge ? __('admin.ops_health.snapshot_age', ['age' => $snapshotAge]) : __('admin.ops_health.snapshot_missing'); return [ 'snapshotMissing' => false, 'connection' => (string) ($snapshot['connection'] ?? config('queue.default')), 'snapshotLabel' => $snapshotLabel, 'queues' => $queues, 'alerts' => $alerts, 'alertCount' => count($alerts), 'stalledAssets' => (int) ($snapshot['stalled_assets'] ?? 0), 'stalledMinutes' => $stalledMinutes, ]; } private function formatQueue(array $queue): array { $size = (int) ($queue['size'] ?? 0); $failed = (int) ($queue['failed'] ?? 0); $limits = $queue['limits'] ?? []; return [ 'name' => (string) ($queue['queue'] ?? 'default'), 'size' => $size, 'size_label' => $size < 0 ? '-' : number_format($size), 'failed' => $failed, 'failed_label' => number_format($failed), 'severity' => (string) ($queue['severity'] ?? 'unknown'), 'warning' => (int) ($limits['warning'] ?? 0), 'critical' => (int) ($limits['critical'] ?? 0), ]; } private function formatAlert(array $alert): array { return [ 'queue' => $alert['queue'] ?? null, 'type' => (string) ($alert['type'] ?? 'unknown'), 'severity' => (string) ($alert['severity'] ?? 'warning'), 'size' => $alert['size'] ?? null, 'failed' => $alert['failed'] ?? null, 'count' => $alert['count'] ?? null, 'older_than_minutes' => $alert['older_than_minutes'] ?? null, ]; } private function formatSnapshotAge(?string $timestamp): ?string { if (! $timestamp) { return null; } try { return Carbon::parse($timestamp)->diffForHumans(); } catch (\Throwable) { return null; } } }