Common event contract
Fields that keep these queries reusable
- timestamp_utc, job_id, job_name, queue_name, and status
- scheduled_at, started_at, completed_at, duration_ms, and attempt
- error_type, worker_name, item_count, and release
Definitions before SQL
Decisions the query cannot make for you
- 1Choose one identifier that connects every attempt of the same logical job.
- 2Document terminal statuses so stalled-job queries do not flag completed work.
- 3Separate queue wait from execution time before setting thresholds.
Recommended sequence
Build detection first, then diagnosis
Analysis patterns
Make the result explain a decision
Model the job lifecycle
Keep scheduled, started, retried, completed, failed, and discarded outcomes distinct so one query can reconstruct each logical job.
Separate stock from flow
Measure the current backlog independently from jobs created and resolved during each time bucket.
Alert on sustained delay
Use queue age, consecutive missed schedules, or repeated retries instead of a single transient worker error.
Complete recipes
Copy the query, then validate the assumptions
Measure Background Job Retry and Failure Rate
Find unreliable jobs by comparing successful runs, retries, failures, and tail duration.
Which background jobs consume the most retries or still fail?
See SQL and resultFind Stalled Background Jobs With SQL
Join job start and finish events to identify work that exceeded its expected completion window.
Which jobs started but never produced a terminal event?
See SQL and resultMeasure Queue Wait Time by Job
Separate time spent waiting in a queue from execution duration and compare p50 and p95 delay by job name.
Which jobs wait longest before a worker starts them?
See SQL and resultMeasure Dead-Letter Queue Growth
Compare dead-letter creation and resolution to find queues accumulating unrecoverable work.
Which queues are adding dead-letter jobs faster than they are resolving them?
See SQL and resultDetect Missed Cron Schedules
Compare consecutive cron-run events with each schedule interval to find late or missing executions.
Which scheduled jobs ran later than their documented interval?
See SQL and resultDetect Background-Job Retry Storms
Find time buckets where repeated job attempts create disproportionate queue work and failures.
Which job types are spending the most work on retries right now?
See SQL and resultAdapt the event contract before the threshold
Keep the analysis pattern, but validate table names, field types, business definitions, time windows, and minimum-volume rules against your own events. Every published query is also planned and executed against an empty typed table with the pinned engine.