@php $hb = $this->heartbeat; $queueRows = $this->queueDepths; $failedJobsCount = $this->failedJobsCount; $recentFailedJobs = $this->recentFailedJobs; $fqCounts = $this->failureQueueCounts; $recentAbandoned = $this->recentAbandonedFailures; $gmailInboxes = $this->gmailInboxes; $shopifyIntegrations = $this->shopifyIntegrations; $automationFails = $this->recentAutomationFailures; $automationFails24h = $this->automationFailureCount24h; $outboundFails = $this->recentOutboundFailures; $provFailuresCount = $this->provisioningFailuresCount; $recentProvFailures = $this->recentProvisioningFailures; @endphp {{-- ───────────────────────────────────────────────── HEADER ───────────────────────────────────────────────── --}}
{{ __('System Health') }}

{{ __('Platform-wide operational diagnostics. Cross-tenant; read-only; surfaces provider details that customer-facing pages deliberately hide.') }}

{{ __('Refresh the page to update.') }}
{{-- ───────────────────────────────────────────────── SCHEDULER HEARTBEAT ───────────────────────────────────────────────── --}}
{{ __('Scheduler heartbeat') }} {{ ucfirst($hb['state']) }}
{{ __('Last beat') }}
{{ $hb['last_at'] ?? '—' }}
{{ __('Age') }}
@if ($hb['age_seconds'] === null) {{ __('Never run') }} @else {{ $hb['age_seconds'] }} {{ __('seconds') }} @endif
{{ __('Scheduler PID') }}
{{ $hb['pid'] ?? '—' }}
@if ($hb['state'] !== 'healthy')
{{ __('Scheduler appears to be stalled. Confirm cron is calling `php artisan schedule:run` every minute.') }}
@endif
{{-- ───────────────────────────────────────────────── QUEUE DEPTHS ───────────────────────────────────────────────── --}}
{{ __('Queue depths') }}

{{ __('Jobs pending on the database queue, per queue name. Anything > 0 here for more than a few minutes means a worker is not draining that queue.') }}

@foreach ($queueRows as $row) @endforeach
{{ __('Queue') }} {{ __('Pending') }} {{ __('Delayed') }}
{{ $row['queue'] }} {{ $row['pending'] }} {{ $row['delayed'] }}
{{-- ───────────────────────────────────────────────── FAILED JOBS (Laravel built-in) ───────────────────────────────────────────────── --}}
{{ __('Failed jobs') }} {{ $failedJobsCount }} {{ __('total') }}
@if (empty($recentFailedJobs))
{{ __('No failed jobs.') }}
@else
@foreach ($recentFailedJobs as $job) @endforeach
{{ __('Failed at') }} {{ __('Queue') }} {{ __('Exception') }}
{{ $job->failed_at }} {{ $job->queue }} {{ $job->exception_one_liner }}
@endif
{{-- ───────────────────────────────────────────────── FAILURE QUEUE (outbound retries) ───────────────────────────────────────────────── --}}
{{ __('Failure queue (retries)') }}

{{ __('Outbound replies that exhausted the transport fallback chain. Hourly retries run via the failure-queue:retry-due scheduler.') }}

{{ __('Pending') }}
{{ $fqCounts['pending'] }}
{{ __('Abandoned') }}
{{ $fqCounts['abandoned'] }}
{{ __('Succeeded on retry') }}
{{ $fqCounts['succeeded'] }}
@if (collect($recentAbandoned)->isNotEmpty())
@foreach ($recentAbandoned as $row) @endforeach
{{ __('Abandoned at') }} {{ __('Account') }} {{ __('Attempts') }} {{ __('Last reason') }}
{{ $row->abandoned_at?->toIso8601String() ?? '—' }} #{{ $row->account_id }} {{ $row->attempt_count }} / {{ $row->max_attempts }} {{ $row->last_failure_reason ?? '—' }}
@endif
{{-- ───────────────────────────────────────────────── GMAIL INBOXES ───────────────────────────────────────────────── --}}
{{ __('Gmail inboxes') }}

{{ __('Verified Gmail accounts connected to ClearDesk. The 5-minute poll backstop and the daily watch renewal both read these rows.') }}

@if (collect($gmailInboxes)->isEmpty())
{{ __('No Gmail inboxes connected.') }}
@else
@foreach ($gmailInboxes as $inbox) @endforeach
{{ __('Address') }} {{ __('Account') }} {{ __('Watch state') }} {{ __('Last checked') }} {{ __('Watch expires') }}
{{ $inbox->address }} #{{ $inbox->account_id }} {{ ucfirst($inbox->gmail_watch_state?->value ?? 'inactive') }} {{ $inbox->gmail_watch_last_checked_at?->diffForHumans() ?? '—' }} {{ $inbox->gmail_watch_expires_at?->diffForHumans() ?? '—' }}
@endif
{{-- ───────────────────────────────────────────────── SHOPIFY INTEGRATIONS ───────────────────────────────────────────────── --}}
{{ __('Shopify integrations') }} @if (collect($shopifyIntegrations)->isEmpty())
{{ __('No enabled Shopify integrations.') }}
@else
@foreach ($shopifyIntegrations as $row) @php $settings = is_array($row->settings) ? $row->settings : []; $histState = data_get($settings, 'sync.orders.state', '—'); $lastInc = data_get($settings, 'incremental.orders.last_success_at', null); @endphp @endforeach
{{ __('Account') }} {{ __('Store') }} {{ __('Historical sync') }} {{ __('Last incremental') }}
#{{ $row->account_id }} {{ $row->store_id ?? __('account-level') }} {{ $histState }} {{ $lastInc ?? '—' }}
@endif
{{-- ───────────────────────────────────────────────── AUTOMATION FAILURES ───────────────────────────────────────────────── --}}
{{ __('Automation failures') }} {{ $automationFails24h }} {{ __('in 24h') }}
@if (collect($automationFails)->isEmpty())
{{ __('No automation failures.') }}
@else
@foreach ($automationFails as $row) @endforeach
{{ __('When') }} {{ __('Account') }} {{ __('Rule') }} {{ __('Error') }}
{{ $row->finished_at?->diffForHumans() ?? '—' }} #{{ $row->account_id }} #{{ $row->automation_id }} {{ data_get($row->error_json, 'message', '—') }}
@endif
{{-- ───────────────────────────────────────────────── RECENT OUTBOUND DELIVERY FAILURES ───────────────────────────────────────────────── --}}
{{ __('Outbound delivery failures') }}

{{ __('Customer-bound replies marked failed after exhausting all transports and retry attempts.') }}

@if (collect($outboundFails)->isEmpty())
{{ __('No recent outbound delivery failures.') }}
@else
@foreach ($outboundFails as $msg) @php $reason = data_get($msg->metadata, 'outbound.final_reason') ?? data_get($msg->metadata, 'outbound.last_reason') ?? '—'; @endphp @endforeach
{{ __('Sent at') }} {{ __('Account') }} {{ __('Ticket') }} {{ __('Last reason') }}
{{ $msg->created_at?->diffForHumans() ?? '—' }} #{{ $msg->account_id }} #{{ $msg->ticket_id }} {{ $reason }}
@endif
{{-- ───────────────────────────────────────────────── PROVISIONING FAILURES (mirror) ───────────────────────────────────────────────── --}}
{{ __('Account provisioning failures') }} {{ $provFailuresCount }} {{ __('total') }}
@if (collect($recentProvFailures)->isEmpty())
{{ __('No provisioning failures.') }}
@else
@foreach ($recentProvFailures as $run) @endforeach
{{ __('Queued at') }} {{ __('Account') }} {{ __('Attempts') }} {{ __('Error') }}
{{ $run->queued_at?->diffForHumans() ?? '—' }} #{{ $run->account_id }} {{ $run->attempt_count }} {{ $run->error_message ?? '—' }}
@endif