Queues and jobs
Register a job, choose a delivery mode, and trace enqueueing, dispatch, and handler execution.
Use a job to run a specific operation in the background. Choose persistent delivery when the work needs a record and recovery. The enqueue receipt reports submission. Use execution records and the resulting state to tell whether the work finished.
Make a job for one specific operation
Suppose a news update needs background processing. Use defineJob to declare its key, payload contract, and version, and defineJobHandler to supply the implementation. In packages/service/features/chat/background.ts, chat.activity.close-periods uses persistent delivery and declares database and telemetry dependencies for its handler.
Export the owning feature’s background contribution and wire it into packages/service/app/background-modules.ts. The producer calls await app.queue() and then queue.enqueue({ job, payload }). The consumer also needs the corresponding definition and handler.
| Delivery mode | Suitable work | Where to look when it fails |
|---|---|---|
| Persistent job | Work that needs a record, retry, or recovery | Job record, dispatch attempt, and consumer logs |
| Direct job | Work that can tolerate a single send attempt without a durable record | Enqueue error and consumer logs |
To commit a persistent job with a business write, call prepare, commit the batch containing the job record, and call dispatch. An idempotencyKey requires a stable intentFingerprint. Use dedupeKey when coalescing currently active or unresolved jobs. The two keys are mutually exclusive.
Deploy a payload change
Use compatiblePayloads to decode older versions while deliveries are outstanding. Test an older payload against the updated consumer, then check the new producer. If enqueue succeeds and the expected write is missing, verify the queue and registration on the consumer, then check the handler’s business result. Runtime environments · Domain events