QueueKeeper

Home / Guides

Dead Oban workers

A worker module can sit in the codebase long after the last caller is gone. Nothing fails: there is no exception and, once the Pruner has done its work, maybe no row in oban_jobs. The signal is the absence of a recent enqueue. That is a different question from a cron job that should have run and did not.

Why a worker goes quiet

  • The callers went away. A feature was removed, a path was rewritten, or the worker was renamed, and the old module was left behind.
  • It was never called in this environment. The worker ships in the release but production never enqueues it.
  • It runs rarely. A monthly or yearly job looks dead if your window is shorter than its period. That is a false positive, not dead code.

This is about whether work is still enqueued. A worker that is inserted every day but never executes is a stalled queue or a stuck job, not a dead worker.

Check how far back history goes

Oban's Pruner deletes completed, cancelled and discarded jobs older than max_age (60 seconds by default). If finished rows only go back a minute, you cannot tell a worker last used yesterday from one last used last year: both will have no row. Measure the oldest finished insert first, and only then look for dead workers.

SELECT min(inserted_at) AS oldest_finished,
       timezone('utc', now()) - min(inserted_at) AS history
FROM oban_jobs
WHERE state IN ('completed', 'cancelled', 'discarded');

If that history is shorter than the window you care about, do not raise the Pruner's max_age just to feed this check: some sites process millions of jobs a day and prune in seconds. Use the last-seen ledger below, or shrink the window. A "dead worker" list from oban_jobs alone is a guess when history is short.

Find workers with no recent insert

The newest inserted_at per worker, in any state, older than 7 days. Seven is only an example (and the default window in queue_keeper_check): use any positive integer number of days (14, 30, 90, whatever matches how rarely a live worker may legitimately run). Oban stores worker without the Elixir. prefix and timestamps in UTC without a time zone.

SELECT worker,
       max(inserted_at) AS last_inserted,
       timezone('utc', now()) - max(inserted_at) AS since_last,
       count(*) AS rows_kept
FROM oban_jobs
GROUP BY worker
HAVING max(inserted_at) < timezone('utc', now()) - interval '7 days'
ORDER BY last_inserted;

A worker whose jobs were all pruned does not appear. To also catch names you know about but that have no row in the window (including never inserted), start from a list:

SELECT w.worker
FROM (VALUES
  ('MyApp.Workers.HourlySync'),
  ('MyApp.Workers.DailyReport'),
  ('MyApp.Workers.LegacyImport'),
  ('MyApp.Workers.Gone')
) AS w(worker)
WHERE NOT EXISTS (
  SELECT 1 FROM oban_jobs j
  WHERE j.worker = w.worker
    AND j.inserted_at >= timezone('utc', now()) - interval '7 days'
);

Oban does not index worker or inserted_at, so these queries read the whole table. Swap 7 days for any other positive integer number of days in both places.

What to do with a quiet worker

  • Confirm it is not a rare job. If it is meant to run every 40 days, do not treat a 7-day silence as unused code.
  • Look for leftover work first. A worker with no recent enqueue can still have jobs scheduled years ahead, or jobs sitting in a queue whose consumer config was removed.
  • Search the codebase for Worker.new / Oban.insert callers and for the module name. If nothing enqueues it and it is not in the crontab, treat it as a review candidate, not proven dead code.
  • Do not confuse this with a cron entry you still expect to run; that is a missing cron job and should be alerted as such.

A last-seen ledger that does not need more retention

Oban core deletes finished jobs (default max_age is 60 seconds). Oban Pro's pruner, unless a rule sets archive: true, also deletes (default: the 1,000 most recent finished jobs). Postgres itself does not keep a per-worker history after DELETE. So the check cannot see a 7-day window in oban_jobs on an aggressively pruned database.

queue_keeper_check includes an opt-in last-seen ledger (since 0.3.0): a tiny table with one row per worker, updated as jobs are inserted. You do not change your Pruner settings. Default QueueKeeperCheck.run/2 stays read-only; writing is a separate, explicit step.

# Migration in the host app (the library never migrates your database itself)
defmodule MyApp.Repo.Migrations.AddQueueKeeperLedger do
  use Ecto.Migration
  def up, do: QueueKeeperCheck.Ledger.Migration.up()
  def down, do: QueueKeeperCheck.Ledger.Migration.down()
end

# In the application supervisor, on every node that inserts jobs
{QueueKeeperCheck.Ledger, repo: MyApp.Repo, prefix: "public", backfill: true}

The handler listens for Oban insert telemetry, coalesces sightings in ETS, and flushes one upsert per worker every few seconds. Several nodes are safe (GREATEST). The check then reads this table and stays silent until the ledger itself has been recording for window_days. Optional backfill: true copies whatever is still in oban_jobs once.

A code scan for leftover modules

mix queue_keeper.dead_code lists compiled Oban.Worker modules with no static call sites and not in the Oban or Oban Pro crontab from application config. Those modules are review candidates, not proven dead code. The report includes coverage (beams scanned, missing debug info). It needs the project compiled; it does not start the application or Oban.

A worker enqueued only through dynamic dispatch (a module name built at runtime with Module.concat, apply/3 on a string, or a name from the database) will show up here even if production still runs it. Runtime-only Pro cron rules stored in the database are not visible. Missing BEAM debug info makes the scan incomplete. JSON output includes review_candidates and a deprecated dead alias for the same list.

Reconcile leftover jobs with what you actually deploy

No recent enqueue is not the same question as "can this job still run?" Opt-in :persisted_jobs compares leftover nonterminal jobs (including future-scheduled work and the core suspended state) to a trusted inventory of workers and queues you pass in. Findings are warnings, with a reason of missing worker, unconfigured queue, paused queue, no active consumer, or insufficient evidence.

Pause and consumer state come only from those options, not from the Oban process on this node. A single Release or mix check starts only the repo and must not be taken as proof that no node still consumes a queue. If you use dynamic queues and have not listed them all, set dynamic_queues: :unknown (the default) so an unlisted queue is insufficient evidence, not "unconfigured." During a worker rename, put the old name in previous_workers. One run covers one Oban prefix. Oban Pro behaviour beyond core suspended is untested and unverified.

Walls that show up on large or Pro setups

  • Aggressive pruning (core 60 s default, Pro count-based 1,000, deprecated DynamicPartitioner dropping old partitions). The ledger is the workaround for dead workers; other history-based checks still need a window that fits retention.
  • High-volume tables. Oban does not index worker or inserted_at, so a GROUP BY worker on oban_jobs is a sequential scan, bounded by the statement timeout. The ledger read is one row per worker.
  • Multiple prefixes or Oban instances. One check run (and one ledger process) covers one prefix. Run once per prefix, and attach the ledger with that prefix.
  • Pro archive. oban_jobs_archive is only there if a pruner rule set archive: true; the checker does not read it. The ledger records inserts before those rows are archived. Oban Pro is untested here; claims above come from public docs.

How queue_keeper_check detects this

:dead_workers is opt-in in queue_keeper_check 0.4.1 (on Hex). Set window_days to any positive integer (7, 14 and 30 are common examples, not a fixed menu). If you only set known or discover: true, the window now defaults to 7 days (it was 14 in 0.3.0; set window_days: 14 to keep the old default). When the ledger is attached, last enqueue comes from that table; otherwise the check reads the newest inserted_at on oban_jobs. If leftover nonterminal or future-scheduled jobs remain, the finding says so: that is enqueue inactivity, not unused code. Always a warning, never critical. Inactivity here is a strict age > window: exactly N days does not fire.

QueueKeeperCheck.run(MyApp.Repo,
  dead_workers: [
    window_days: 7,
    ignore: ["MyApp.Workers.YearlyClose"],
    overrides: %{"MyApp.Workers.MonthlyReport" => 40},
    known: ["MyApp.Workers.LegacyImport"]
  ]
)
  • It uses last enqueue (inserted_at), not last execution (attempted_at). A worker that is still being inserted is not unused. Leftover pending and future-scheduled jobs are reported alongside inactivity.
  • If the ledger (or, without it, finished-job history) is younger than a worker's window, that worker is not flagged. Set report_short_history: true if you want a warning about the short history instead of silence. Attach the ledger; do not raise Pruner max_age just for this check.
  • Workers listed in cron_missing.expected are skipped, so a late cron job is reported as missing, not as dead.
  • Optional discover: true also checks Oban.Worker modules in loaded non-OTP applications. That needs the host application started; mix queue_keeper.check and QueueKeeperCheck.Release do not start it.
  • Without a ledger, the oban_jobs fallback has no index support: a sequential scan, bounded by the statement timeout.

For a higher-signal review, opt-in :dead_worker_candidates combines both signals. A finding is high confidence only when there has been no enqueue for at least the window (inclusive; default 7 days) with enough history, the worker has no code or cron reference, the static scan is complete, and no leftover pending or future-scheduled jobs remain. It never claims a worker is definitely dead. If history is shorter than the window, the result is unknown, not proof of inactivity. Workers that are still referenced, or that still have pending or future jobs, are reported at lower confidence. Dynamic dispatch, runtime-only cron, and jobs that run less often than the window remain caveats. Oban Pro beyond the core suspended state is untested.

QueueKeeperCheck.run(MyApp.Repo,
  dead_worker_candidates: [
    window_days: 7,
    known: ["MyApp.Workers.LegacyImport"],
    ignore: ["MyApp.Workers.YearlyClose"],
    scan: [apps: [:my_app]]
  ]
)
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.

Documentation on HexDocs · Source on GitHub · Hex package

Related guides