jobs.dispatch(...)
Use jobs.dispatch(...) to move due work from storage into the queue.
This includes:
- one-shot runs whose scheduled time has arrived
- recurring schedules whose next run is due
Signature
await jobs.dispatch({ limit? });Return shape:
{ dispatched: number }Example
const result = await jobs.dispatch({ limit: 100 });
console.log(result.dispatched);In Cloudflare Workers, this is usually called through:
await runtime.dispatchScheduled({ db, queue });What It Dispatches
jobs.dispatch(...) checks two kinds of due work:
- due recurring schedules
- due scheduled job runs
For recurring schedules, dispatch does more than queue a message. It first materializes a new run from the schedule, advances the schedule to its next occurrence, and then queues the new run.
For one-shot delayed jobs, dispatch simply moves the run from scheduled to queued and sends the queue message.
Behavior
For recurring schedules:
- read due schedules
- calculate the next occurrence
- advance the schedule row
- create a new run linked to that schedule
- move the new run to
queued - send a queue message
For ordinary scheduled runs:
- read due job runs
- move each run to
queued - send a queue message
limit
Use limit to cap how many due items are processed in one dispatch call.
await jobs.dispatch({ limit: 50 });If omitted, the current default is 100.
When To Use It
Use jobs.dispatch(...) when your environment needs an explicit dispatch step between storage and execution.
In Cloudflare Workers, wire the dispatcher tick to the Worker scheduled() handler and call runtime.dispatchScheduled(...).
Notes
jobs.dispatch(...) does not execute handlers directly. It only moves due work into the queue.
Actual handler execution happens later through jobs.consume(...) or runtime.consumeBatch(...).