*/ protected function getStats(): array { $window = SystemConsoleWindow::fromNullable((string) request()->query('window')); $start = $window->startAt(); $baseQuery = OperationRun::query()->where('created_at', '>=', $start); $totalRuns = (clone $baseQuery)->count(); $activeRuns = (clone $baseQuery) ->whereIn('status', [ OperationRunStatus::Queued->value, OperationRunStatus::Running->value, ]) ->count(); $failedRuns = (clone $baseQuery) ->where('status', OperationRunStatus::Completed->value) ->where('outcome', OperationRunOutcome::Failed->value) ->count(); $stuckRuns = app(StuckRunClassifier::class) ->apply((clone $baseQuery)) ->count(); return [ Stat::make('Runs in window', $totalRuns) ->description($window::options()[$window->value] ?? 'Last 24 hours') ->url(SystemOperationRunLinks::index()), Stat::make('Active', $activeRuns) ->color($activeRuns > 0 ? 'warning' : 'gray') ->url(SystemOperationRunLinks::index()), Stat::make('Failed', $failedRuns) ->color($failedRuns > 0 ? 'danger' : 'gray') ->url(SystemOperationRunLinks::index()), Stat::make('Stuck', $stuckRuns) ->color($stuckRuns > 0 ? 'danger' : 'gray') ->url(SystemOperationRunLinks::index()), ]; } }