Triggering from your app
Schedules
Run a task on a cron, in a time zone. Declare one schedule on the task itself, or create as many as you need from your backend, such as one per customer.
On this page
- Declare a schedule
- Choose the environments
- Discovered schedules fire in prod only
- What a deploy does to schedules
- Create schedules from your backend
- Read a schedule
- List schedules
- Pause, change and delete
- From the CLI
- What a scheduled run receives
- Find scheduled runs
- When a schedule fires
- Cron syntax
- Time zones and daylight saving
- Limits
A schedule starts a run of a task on a cron, in a time zone. There are two kinds:
| Kind | Where it lives | Use it for |
|---|---|---|
| Declared | schedule in the task's definition, deployed with your code | One timetable per task, such as a nightly report. |
| Created through the API | schedules.create, called from your backend | Timetables that come from your data, such as one per customer. |
Both start ordinary runs of an ordinary task. You can still trigger a scheduled task yourself, with any payload.
Declare a schedule#
Add schedule to the task's definition:
{"id": "reports.digest", "kind": "task", "runtime": "node", "entrypoint": "tasks/digest.mjs", "handler": "sendDigest", "schedule": {"cron": "0 6 * * *", "timezone": "America/Denver"}}import { writeFileSync } from 'node:fs';import { defineTask } from '@bokjoy/sdk'; // Every day at 06:00 in Denver. Without `environments`, prod only.const digest = defineTask({ id: 'reports.digest', kind: 'task', runtime: 'node', entrypoint: 'tasks/digest.mjs', handler: 'sendDigest', schedule: { cron: '0 6 * * *', timezone: 'America/Denver' },}); writeFileSync('manifest.json', JSON.stringify({ tasks: [digest] }, null, 2));import json from bokjoy import define_task # Every day at 06:00 in Denver. Without "environments", prod only.digest = define_task( id="reports.digest", kind="task", runtime="python", entrypoint="tasks/digest.py", handler="send_digest", schedule={"cron": "0 6 * * *", "timezone": "America/Denver"},) with open("manifest.json", "w") as manifest: json.dump({"tasks": [digest]}, manifest, indent=2)| Field | Meaning |
|---|---|
cron | Required. Five fields: minute, hour, day of month, month and day of week. See Cron syntax. |
timezone | Optional. An IANA name, such as America/Denver or Europe/London. Default: UTC. |
environments | Optional. Any of dev, staging, prod and preview. Default: ["prod"], for a schedules.task too. |
defineTask and define_task refuse a bad cron, or a time zone your computer does not know, when you build the manifest. The control plane checks the time zone again when you deploy.
A task has at most one schedule. A list in the cron covers several times a day: 0 6,18 * * * fires at 06:00 and at 18:00. For anything more, create schedules from your backend.
schedule is part of the task's definition, like hot, so changing it takes a new deploy.
Choose the environments#
A declared schedule fires only in prod unless you name other environments. dev and staging are long-lived environments, so a schedule there would run unreleased code against real services on every tick. To fire in staging too, name both:
{"cron": "0 6 * * *", "timezone": "America/Denver", "environments": ["staging", "prod"]}- It fires where its deployment is current. Each environment it names fires it while that environment's current deployment declares it.
- Each environment fires on its own. A deployment current in both
stagingandprod, with both named, starts two runs per tick, one in each, each with its own variables. - Previews run a schedule only when it names
preview. It then fires in every preview where its deployment is current, each with its own schedule and runs. Archiving a preview stops its schedules and removes them. Unarchiving it starts them again from their next tick. - Schedules you create from your backend never run in previews.
- On your own computer,
durable-compute servemakes your code current indev. Namedevto see a schedule fire there.
Discovered schedules fire in prod only#
A schedules.task that deploy finds in build.dirs fires in prod only when its cron names no environments. This differs from Trigger.dev on purpose. Trigger.dev fires such a schedule in every environment. On Bok Joy, staging and previews are long-lived and run against real services, so a poller there could take work meant for production. To fire in staging or previews too, name them in the cron:
import { schedules } from '@bokjoy/sdk/trigger'; export const digest = schedules.task({ id: 'reports.digest', cron: { pattern: '0 6 * * *', environments: ['PRODUCTION', 'STAGING', 'PREVIEW'] }, run: async (payload) => ({ at: payload.timestamp.toISOString() }),});PRODUCTION, STAGING, DEVELOPMENT and PREVIEW become prod, staging, dev and preview. Deploy prints one line per discovered cron that says where it fires, and whether that includes the environment you deploy to.
What a deploy does to schedules#
Whenever a deployment becomes current in an environment, through a deploy with --env, a promote or a local serve, Bok Joy updates that environment's declared schedules in the same step:
| The new deployment | The schedule |
|---|---|
| Keeps the task's schedule as it was | Carries on, with the same ID, pause state and lastTimestamp. |
| Changes its cron or time zone | Keeps its ID, pause state and lastTimestamp, and fires next at its first tick after the deploy. |
| Drops the schedule or the task, or stops naming this environment | Stops. Declaring it again later brings back the same schedule. |
| Adds a schedule | Fires first at its first tick after the deploy. |
There is no backfill: a new or changed schedule never fires for times before the deploy. A tick decided after the deploy runs the new deployment's code.
Create schedules from your backend#
schedules creates, reads, changes, pauses and deletes schedules in your API key's environment. The calls have Trigger.dev's names:
import { schedules } from '@bokjoy/sdk'; // One schedule per customer, in the customer's own time zone.const schedule = await schedules.create({ task: 'reports.digest', cron: '0 9 * * MON-FRI', timezone: 'Europe/London', externalId: 'customer-42', // Running this again updates the schedule instead of adding one. deduplicationKey: 'digest-customer-42',});console.log(schedule.id, schedule.type, schedule.nextRun); // The next ticks, and the newest ticks Bok Joy has decided.const details = await schedules.retrieve(schedule);console.log(details.upcoming.join(' '));for (const tick of details.ticks) { console.log(tick.timestamp, tick.outcome, tick.runId ?? tick.reason);}from bokjoy import schedules # One schedule per customer, in the customer's own time zone.schedule = schedules.create( task="reports.digest", cron="0 9 * * MON-FRI", timezone="Europe/London", external_id="customer-42", # Running this again updates the schedule instead of adding one. deduplication_key="digest-customer-42",)print(schedule.id, schedule.type, schedule.next_run) # The next ticks, and the newest ticks Bok Joy has decided.details = schedules.retrieve(schedule)print(" ".join(details.upcoming))for tick in details.ticks: print(tick.timestamp, tick.outcome, tick.run_id or tick.reason)| Node | Python | Meaning |
|---|---|---|
task | task | Required. A task in the environment's current deployment. |
cron | cron | Required. See Cron syntax. |
timezone | timezone | Optional. An IANA name. Default: UTC. |
externalId | external_id | Optional. 1 to 128 bytes of your own, such as a customer ID. Every run's payload carries it. |
deduplicationKey | deduplication_key | Optional. 1 to 128 bytes. Names the schedule, so creating it again updates it. |
- A new schedule fires first at its first tick after now.
- A
deduplicationKeythat names a live schedule in the environment makescreateupdate that schedule and return it. Name the key after what the schedule is for, such asdigest-customer-42, so setup code that runs twice never makes two. - Without a key, the client makes one per call and sends it again on its own retries, so a network retry never makes a second schedule. Two calls make two schedules.
- Errors. A task the environment's current deployment lacks, a bad cron and an unknown time zone are each a
ValidationError. So is a 1,001st schedule in an environment. An environment with no current deployment is aConflictError.
Read a schedule#
schedules.retrieve takes a schedule or its ID, and returns the schedule with its next ticks and its newest decided ticks:
| Node | Python | Value |
|---|---|---|
id | id | The schedule. Each run's payload carries it as scheduleId. |
type | type | DECLARATIVE for a declared schedule, IMPERATIVE for one created through the API. |
task, cron, timezone | task, cron, timezone | What it runs, and when. |
active | active | False while paused. |
externalId, deduplicationKey | external_id, deduplication_key | What a schedule was created with through the API. Null on a declared schedule. |
environment, deploymentId | environment, deployment_id | Where it fires. deploymentId is the deployment that declares it, or null. |
nextRun | next_run | Its next tick. Null while paused. |
lastTimestamp, lastRunId | last_timestamp, last_run_id | The last tick that started a run, and that run. |
upcoming | upcoming | The next 5 ticks. Empty while paused. Only from retrieve. |
ticks | ticks | The newest 20 decided ticks, newest first. Only from retrieve. |
Each tick says what happened:
| Node | Python | Value |
|---|---|---|
timestamp | timestamp | The tick. |
outcome | outcome | fired or skipped. |
runId, runStatus | run_id, run_status | The run it started, and that run's status now. |
reason | reason | Why it was skipped. See When a schedule fires. |
missedSince | missed_since | Set when the tick stands for missed ticks too: the first of them. |
decidedAt | decided_at | When Bok Joy decided it. |
Times are RFC 3339 strings in UTC. For ticks older than the newest 20, page through GET /v1/schedules/{id}/ticks.
List schedules#
schedules.list lists both kinds, paused ones too, oldest first. A deleted schedule is never listed.
import { schedules } from '@bokjoy/sdk'; // Numbered pages, as Trigger.dev's schedules.list answers.const page = await schedules.list({ task: 'reports.digest', page: 1, perPage: 50 });const { currentPage, totalPages, count } = page.pagination;console.log(`page ${currentPage} of ${totalPages}, ${count} schedules`); // Or follow a cursor through every page.let cursor;do { const next = await schedules.list({ limit: 200, cursor }); for (const schedule of next.data) { console.log(schedule.id, schedule.cron, schedule.active); } cursor = next.nextCursor ?? undefined;} while (cursor);from bokjoy import schedules # Numbered pages, as Trigger.dev's schedules.list answers.page = schedules.list(task="reports.digest", page=1, per_page=50)numbers = page.paginationprint(f"page {numbers.current_page} of {numbers.total_pages}, {numbers.count} schedules") # Or follow a cursor through every page.cursor = Nonewhile True: current = schedules.list(limit=200, cursor=cursor) for schedule in current.data: print(schedule.id, schedule.cron, schedule.active) cursor = current.next_cursor if cursor is None: break- Numbered pages are the default, as in Trigger.dev:
pagefrom 1, andperPage(Python:per_page) from 1 to 200, default 50. The answer'spaginationhascurrentPage,totalPagesandcount. - A cursor is the other way: pass
limit(1 to 200) orcursor. The answer'snextCursor(Python:next_cursor) is the next page's cursor, or null on the last page. tasklists one task's schedules.
Mixing the two kinds of paging is a ValidationError.
Pause, change and delete#
// Run with: node manage.mjs <schedule id>import { schedules } from '@bokjoy/sdk'; const id = process.argv[2]; // Pause, then resume. It resumes at its next tick: the paused span never fires.const paused = await schedules.deactivate(id);const resumed = await schedules.activate(id);console.log(paused.active, resumed.active, resumed.nextRun); // Replace the task, cron, time zone and external ID. A field you leave out// goes back to its default: UTC, and no external ID.const moved = await schedules.update(id, { task: 'reports.digest', cron: '0 8 * * MON-FRI', timezone: 'Europe/London', externalId: 'customer-42',});console.log(moved.cron, moved.nextRun); // Stop it for good. The runs it started stay.await schedules.del(id);# Run with: python manage.py <schedule id>import sys from bokjoy import schedules schedule_id = sys.argv[1] # Pause, then resume. It resumes at its next tick: the paused span never fires.paused = schedules.deactivate(schedule_id)resumed = schedules.activate(schedule_id)print(paused.active, resumed.active, resumed.next_run) # Replace the task, cron, time zone and external ID. A field you leave out# goes back to its default: UTC, and no external ID.moved = schedules.update( schedule_id, task="reports.digest", cron="0 8 * * MON-FRI", timezone="Europe/London", external_id="customer-42",)print(moved.cron, moved.next_run) # Stop it for good. The runs it started stay. Python names it delete,# since del is a keyword.schedules.delete(schedule_id)| Call | Declared schedule | Created through the API |
|---|---|---|
deactivate | Pauses it. It stays paused across deploys. | Pauses it. |
activate | Resumes it. | Resumes it. |
update | ConflictError: change schedule in the task's definition and deploy. | Replaces task, cron, time zone and external ID. |
del (Python: delete) | ConflictError: remove schedule from the task and deploy. | Stops it for good. |
- Resuming starts at the first tick after now. The paused span never fires, and never counts as missed.
updatereplaces all four fields. A time zone you leave out goes back toUTC, and an external ID you leave out is cleared. A new cron or time zone fires next at its first tick after now. A paused schedule stays paused.- Deleting stops the schedule at once, and its runs stay. It then answers
NotFoundError, and Bok Joy removes it, with its ticks, 30 days later by default. - Another environment. A schedule outside the key's environment answers
NotFoundError, exactly like one that does not exist.
From the CLI#
durable-compute schedules list --task reports.digestdurable-compute schedules show <schedule id>durable-compute schedules create --task reports.digest --cron '0 9 * * MON-FRI' \ --timezone Europe/London --external-id customer-42 --deduplication-key digest-customer-42durable-compute schedules pause <schedule id>durable-compute schedules resume <schedule id>durable-compute schedules delete <schedule id>With an API key in DC_API_TOKEN, the CLI acts in that key's environment.
What a scheduled run receives#
Each run's payload has the fields of Trigger.dev's scheduled task payload, so a Trigger.dev handler can read it unchanged. Times are RFC 3339 strings in UTC, not Date objects, because a payload is JSON.
For a schedule created through the API with the cron 0 6,12 * * * in UTC and the external ID pos-7, the run for 12:00 on October 8, 2026 receives:
{"type": "IMPERATIVE", "timestamp": "2026-10-08T12:00:00Z", "lastTimestamp": "2026-10-08T06:00:00Z", "timezone": "UTC", "scheduleId": "6f1c2b8e-0d4a-4c1e-9f3b-2a7d5e8c9b10", "externalId": "pos-7", "upcoming": ["2026-10-09T06:00:00Z", "2026-10-09T12:00:00Z", "2026-10-10T06:00:00Z", "2026-10-10T12:00:00Z", "2026-10-11T06:00:00Z"]}| Field | Value |
|---|---|
type | DECLARATIVE for a declared schedule, IMPERATIVE for one created through the API. |
timestamp | The tick this run is for. A run that starts late still gets its own tick. |
lastTimestamp | The last tick that started a run. Left out on the schedule's first run. |
timezone | The schedule's time zone. |
scheduleId | The schedule's ID. |
externalId | The schedule's external ID. Left out when it has none. |
upcoming | The next 5 ticks after this one. |
A field is left out rather than null. In TypeScript, the payload's type is ScheduledPayload from @bokjoy/sdk.
Read the time window from the payload, not from the clock. Then a run that starts late, or one that stands for missed ticks, still covers the right span:
import { sendEmail } from './mailer.mjs'; // A scheduled run's payload says which tick it is for.export async function sendDigest(payload) { const { timestamp, lastTimestamp } = payload ?? {}; // The tick, not the moment the run started, so a late run still // covers its own window. A run you trigger by hand has no tick. const to = timestamp ?? new Date().toISOString(); // The last tick that fired a run. The first run has none. const from = lastTimestamp ?? null; await sendEmail('team@example.com', 'digest', { from, to }); return { from, to };}from datetime import datetime, timezone from mailer import send_email # A scheduled run's payload says which tick it is for.def send_digest(payload, ctx): payload = payload or {} # The tick, not the moment the run started, so a late run still # covers its own window. A run you trigger by hand has no tick. to = payload.get("timestamp") or datetime.now(timezone.utc).isoformat() # The last tick that fired a run. The first run has none. since = payload.get("lastTimestamp") send_email("team@example.com", "digest", {"from": since, "to": to}) return {"from": since, "to": to}Find scheduled runs#
- In the console, the Runs page's Source filter has a Schedule option, and a scheduled run's Source is Schedule.
- Over the API, a scheduled run's idempotency key is
schedule:<schedule id>:<tick>, such asschedule:6f1c2b8e-0d4a-4c1e-9f3b-2a7d5e8c9b10:2026-10-08T12:00:00Z. These keys are reserved: a trigger whose key starts withschedule:is aValidationError. - In a run stream, the run's
run.createdevent has the originschedule.
When a schedule fires#
Bok Joy looks for due ticks once a second. A due tick starts its run at once, on the environment's current deployment with the environment's variables, the task's own size and the default placement, private-first. The run then waits for a worker like any other run.
- At most one run per tick. Each tick of a schedule starts at most one run, even across restarts. A tick that falls due while Bok Joy restarts fires as soon as it is back, late, with its own
timestamp. - Overlap is skipped. When the schedule's previous run is still delayed, queued, running or waiting, the tick is skipped, and its reason names that run. A workflow asleep or waiting for an event counts as unfinished. The next run's
lastTimestampstill points at the last tick that started a run, so it sees the gap. - Missed ticks start one run. When several ticks of a schedule fell due while Bok Joy could not fire them, it starts one run, for the latest. That tick's
missedSincenames the first missed one, and the run'slastTimestampcovers the whole gap. - Other skips. A tick is also skipped, with its reason, when the task is missing from the environment's current deployment, when the environment has no current deployment, or when the run is refused. The schedule carries on at its next tick.
- Retries. A scheduled run retries like any run, so give side effects a key, such as
ctx.idempotencyKey.
Cron syntax#
A cron is five fields separated by single spaces:
| Field | Values |
|---|---|
| Minute | 0 to 59 |
| Hour | 0 to 23 |
| Day of month | 1 to 31 |
| Month | 1 to 12, or JAN to DEC |
| Day of week | 0 to 7, or SUN to SAT. 0 and 7 are both Sunday. |
Each field is *, a number, a range such as 1-5, a list such as 6,18, or a step over * or a range, such as */15 or 0-30/10. Names are three letters, in any case.
| Cron | Fires |
|---|---|
*/15 * * * * | Every 15 minutes |
0 6,18 * * * | At 06:00 and 18:00 |
0 9 * * MON-FRI | At 09:00 on weekdays |
0 0 1 * * | At midnight on the first of each month |
When both day fields name days, a day that matches either one counts, as in classic cron. 0 0 1 * MON fires on the first of each month and on every Monday.
Bok Joy refuses:
- seconds, nicknames such as
@hourly, andL,W,#,?and+ - a step on a single number, such as
0/10 * * * *. Write*/10 * * * *instead. - a range that runs backwards, such as
MON-SUNorDEC-JAN - a stepped
*in one day field while the other names days, such as0 0 */2 * MON, since cron implementations disagree on what it means. Use a range:0 0 1-31/2 * MON. - a cron that never fires, such as
0 0 30 2 *
The shortest interval is one minute.
Time zones and daylight saving#
A schedule follows the wall clock of its time zone. A schedule in UTC never meets a daylight saving change. In a zone that has them, Bok Joy follows classic cron's rule:
- A cron is a fixed time of day unless its minute or hour field starts with
*.30 2 * * *,0 6,18 * * *and0-5 2 * * *are fixed times.*/15 * * * *and0 * * * *are not. - When the clock jumps forward past a fixed time, that time fires once, at the first moment after the jump. Several fixed times inside the skipped span fire once, together.
- When the clock falls back and repeats a fixed time, it fires only the first time.
- A cron that is not a fixed time follows real time. It skips the times that never happen, and fires at each real occurrence of a repeated one, so
0 * * * *fires every real hour.
Cron, in America/Denver | March 8, 2026: 02:00 jumps to 03:00 | November 1, 2026: 01:00 to 02:00 happens twice |
|---|---|---|
30 2 * * * | Fires once, at 03:00 | Fires once, at 02:30 |
30 1 * * * | Fires once, at 01:30 | Fires once, at the first 01:30 |
*/15 * * * * | Skips 02:00 to 02:45 | Fires at both 01:00s, both 01:15s, and so on |
0 * * * * | Skips 02:00 | Fires at both 01:00s |
The time zone rules are built into Bok Joy, so a country's new rules reach your schedules with a Bok Joy release.
Limits#
A cron is at most 100 bytes, and a time zone name at most 64. An environment holds up to 1,000 schedules created through the API. Decided ticks are kept for 30 days by default, and a schedule always keeps its latest fired tick. See Limits for the rest.
Coming from Trigger.dev? See Scheduled tasks for what changes.