Included in every project
Generated projects ship with a background job queue stored in the project's
own Postgres database. There is no option to select at generation time and
nothing to install: no Redis, no Postgres extension, no extra service. The
queue is part of the shared shiprust-core crate, the jobs table comes
from the project's migrations, and the worker starts inside the web process
by default.
Jobs are rows with a payload and a handler. Enqueue one from a request, inside the same transaction as the data it belongs to, and the worker runs it later, retrying with backoff if it fails. Queued jobs survive crashes, restarts and deploys.
What you get
- A
Jobtrait: a serde struct with a stableKIND,MAX_ATTEMPTS,TIMEOUTand an asyncrunhandler that receives your app state. enqueue(&mut *tx, &job, options)with optionalrun_atdelay anddedupe_key, usable with a pool, connection or transaction.- A worker with
FOR UPDATE SKIP LOCKEDclaims, 60-second leases kept alive by heartbeats, exponential backoff, dead-letter rows, graceful shutdown that drains running jobs, and retention of finished rows. cargo run -- jobs statsandcargo run -- jobs retry <id>.JOBS_WORKER=true|false|onlyand aworkercommand, so the same image runs jobs in the web container or in a separate one.- An example job, a welcome email after signup verification, with an end-to-end test that runs the worker against a local mail double.
Handlers run at least once; the project guide explains how to keep them idempotent and when to use a job instead of the request handler, the bounded CPU helper or a Tokio interval.
Before retrying a dead job
Retry a dead job only after fixing its cause and checking whether its external
side effect already happened. A fresh attempt budget is not proof that another
email or API request is safe. This checklist follows ShipRust's queue and operator
commands at revision 3d49d62, reviewed November 5, 2026.
Start with cargo run -- jobs stats from your generated application's workspace,
with its database configuration loaded. This groups counts by state and kind; it
does not list individual job IDs. Inspect the specific row in your database and
correlate it with the job.run trace before deciding what to retry.
| What you find | What to check before acting |
|---|---|
queued, with a future run_at | It may be intentionally delayed. A queued job is not eligible for the dead-job retry command. |
queued and overdue | Confirm a worker is running, recognizes the kind and can reach the database. Resetting attempts does not register a missing handler. |
running | Inspect the lease and worker. A later sweep returns expired work to queued, or to dead when attempts are exhausted. Do not rewrite a running row into a new attempt. |
dead, with a retryable provider failure | Fix the provider/configuration problem and establish whether the previous request was accepted before replaying it. |
dead, with invalid payload or a discarded error | Check compatibility with the deployed handler. Repeating unchanged bad input does not repair it. |
done | Check the handler's success conditions. The welcome-email example can succeed without sending when the user no longer exists; console delivery sends no real email. |
For the selected dead row, retain its ID, kind, attempts, max_attempts,
last_error and relevant timestamps privately before retrying. Check its
dedupe_key: another queued or running row with the same kind and non-null key
can make the retry fail its uniqueness constraint. Do not delete that other row
to force a replay. Payloads, errors and traces may contain application data; they
do not belong in a public incident report.
Once the cause and replay decision are resolved, replace <id> with that dead
job's UUID:
cargo run -- jobs retry <id>
The command queues only a dead job, resets its attempts to zero, makes it due now,
and clears last_error and finished_at. It neither repairs the payload nor
reverses an external effect. A worker must still claim and run it. Verify the row's
new state and the destination's result; a successful CLI response means queued, not delivered.
If the provider might already have accepted an earlier request, reconcile that operation first. Reuse the same business-operation key where the destination supports idempotency. ShipRust's queue dedupe key prevents overlapping enqueues; it does not make external delivery exactly once. The supplied welcome-email handler does not send a provider idempotency key.
Keep a short private recovery record: job ID, original error, cause fixed, external-acceptance evidence, replay decision and observed result. Done rows are eligible for retention cleanup after seven days and dead rows after thirty; the queue is not a permanent incident archive.
The supplied regression
failures_back_off_then_die_and_can_be_retried_by_an_operator in
crates/core/src/jobs/worker.rs checks exhaustion, discard and dead-only retry
bookkeeping. Its failing handler can exhaust the new budget again: resetting
attempts is not a repair. Use a disposable database and a local provider double
for your own recovery test. This checklist is source-reviewed guidance, not a
report that your generated application or provider has passed a recovery drill.
Where to read more
The generated project's guide at app/content/docs/background-jobs.md
(also served at /docs/background-jobs in your running app) covers defining
jobs, enqueueing, guarantees, running the worker and operating the queue.
The CapRover and Docker guides in your
project describe the optional separate worker container.
This site runs on the same queue: the purchase confirmation email after a lifetime purchase is a background job. The queue supports both in-process and dedicated workers.
Read how we implement Rust background jobs with a Postgres queue for a code-level walkthrough of transactional enqueueing, leases, retries, and at-least-once delivery.