Background work
This page covers the work your app does outside a request: schedules that run an action on a timer, events an action announces, subscribers that react to them, and what happens when that work fails.
Three things start work, and each one calls an ordinary action, the kind of function that reads and writes stored records:
| Trigger | Starts when | Lives in |
|---|---|---|
| Route | A request arrives | routes/ (HTTP) |
| Schedule | A timer fires | schedules/ |
| Subscriber | An event it listens for is committed | subscribers/ |
All your logic lives in actions, so a reviewer reads one kind of code whatever started it. A schedule or a subscriber only adds when to run and what happens if it fails.
Two more things feed this work without being triggers of their own:
- Work over more items than one action can hold runs as a batch. An action starts it, and it calls an action for each item (Batches).
- The outside world produces events for your subscribers: webhooks, a package's own events and polls, and messages read from a queue (Events from outside).
Much of this page talks about the tick. The tick is the runtime's regular wake-up, once a minute in most apps: it runs the schedules that are due and picks up background work left over (The tick).
| Schedules Use a schedule for work that should happen on a timer rather than when someone asks, such as sending reminders every 15 minutes or tidying up once a day. |
| Batches partly Use a batch when one action can't hold the work: importing every row of an uploaded spreadsheet, writing a large export, or walking every record a query finds or every page of a provider's list. |
| Events How one part of an app tells the others that something happened: declaring an event, emitting it and subscribing to it. |
| Delivery and failure How an event reaches its subscribers, what happens when a subscriber fails, and what the person running the app sees. |
What is built says which of this works today.
Markdown for agents: /docs/jobs-and-events.md.Built from Jadpo main at aee2e8f.