Oban queue backed up or stalled
When jobs sit in a queue longer than they should, there are two different problems. A backlog means the queue is running but not keeping up. A stall means due jobs are waiting and nothing in the queue is being attempted at all. The fixes are different, so measure first.
Which jobs are due
A job is due when it is available, or scheduled or retryable with a scheduled_at in the past. Depth and wait time per queue:
SELECT queue,
count(*) AS due,
timezone('utc', now()) - min(scheduled_at) AS oldest_wait
FROM oban_jobs
WHERE state IN ('available', 'scheduled', 'retryable')
AND (state = 'available' OR scheduled_at <= timezone('utc', now()))
GROUP BY queue
ORDER BY oldest_wait DESC;
Wait time is usually the better signal. A depth of 10,000 is fine if they all arrived a second ago; one job waiting 20 minutes in a latency-sensitive queue is not.
Is anything running?
SELECT queue, count(*) AS executing, max(attempted_at) AS newest_start
FROM oban_jobs
WHERE state = 'executing'
GROUP BY queue;
Then, in a remote console on each node that should run the queue:
Oban.check_queue(queue: :mailers)
#=> %{queue: "mailers", limit: 10, paused: false, running: [...], ...}
# nil if the queue isn't running on this node
Oban.Peer.leader?()
#=> true on exactly one node, normally
A backlog: running, but not keeping up
Due jobs growing, running as long as limit, and recent starts in the query above: the queue works but is too slow. Raise the queue's limit, run it on more nodes, or look for slow jobs. If every slot is held by long-running jobs, see hanging jobs.
A stall: nothing is being attempted
Due jobs are waiting and nothing in the queue started recently. The usual causes:
check_queue/1returnsnilon every node. The queue isn't started: missing fromqueues:in this environment's config, or the nodes that run it aren't deployed.paused: true. Someone or something paused it.Oban.resume_queue(queue: :mailers).- Every slot busy with long-running jobs. Nothing new starts because nothing finishes. Look for hanging or orphaned jobs in that queue.
- Lots of
scheduledorretryablerows well pastscheduled_at. Those jobs aren't being staged toavailable. In Oban 2.24 the leader stages due jobs about once a second, so check leadership and whether Oban is running at all.
SELECT queue, state, count(*) AS overdue
FROM oban_jobs
WHERE state IN ('scheduled', 'retryable')
AND scheduled_at <= timezone('utc', now()) - interval '1 minute'
GROUP BY queue, state;
With Oban Pro, global limits and rate limits hold jobs back on purpose, so a queue can look backed up while doing exactly what you configured.
How queue_keeper_check detects this
Two checks read the same due-job aggregate per queue:
:backlogfires when a queue has more thanmax_depthdue jobs (default 1000) or its oldest due job has waited more thanmax_latency(default 300 seconds). Warning, critical at twice the threshold.:stalledfires when the oldest due job has waited more thanmax_latencyand no job in that queue was attempted in the lastwindowseconds (default 60). Always critical. It also fires when every slot is held by long-running jobs, because nothing new was attempted;:hangingor:orphanedfindings for the same queue point to that case.
QueueKeeperCheck.run(MyApp.Repo,
backlog: [max_depth: 5_000, max_latency: 60],
stalled: [window: 60]
)
:stalled counts recently finished jobs as activity, so if Oban's Pruner deletes them quickly (default max_age 60 seconds) keep its window within what the Pruner keeps.
def deps do
[
{:queue_keeper_check, "~> 0.4.1"}
]
end
queue_keeper_check is a free, MIT-licensed, read-only health check for Oban (v0.4.1, early). It only runs SELECTs on oban_jobs, never reads job args, meta or errors, and sends nothing anywhere. Tested with Oban 2.24 on PostgreSQL 17, SQLite and MySQL 8.4; not tested with Oban Pro.