Skip to content

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

A schedule starts a run of a task on a cron, in a time zone. There are two kinds:

KindWhere it livesUse it for
Declaredschedule in the task's definition, deployed with your codeOne timetable per task, such as a nightly report.
Created through the APIschedules.create, called from your backendTimetables 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:

JSON
{"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));
FieldMeaning
cronRequired. Five fields: minute, hour, day of month, month and day of week. See Cron syntax.
timezoneOptional. An IANA name, such as America/Denver or Europe/London. Default: UTC.
environmentsOptional. 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:

JSON
{"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 staging and prod, 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 serve makes your code current in dev. Name dev to 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:

JavaScript
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 deploymentThe schedule
Keeps the task's schedule as it wasCarries on, with the same ID, pause state and lastTimestamp.
Changes its cron or time zoneKeeps 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 environmentStops. Declaring it again later brings back the same schedule.
Adds a scheduleFires 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);}
NodePythonMeaning
tasktaskRequired. A task in the environment's current deployment.
croncronRequired. See Cron syntax.
timezonetimezoneOptional. An IANA name. Default: UTC.
externalIdexternal_idOptional. 1 to 128 bytes of your own, such as a customer ID. Every run's payload carries it.
deduplicationKeydeduplication_keyOptional. 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 deduplicationKey that names a live schedule in the environment makes create update that schedule and return it. Name the key after what the schedule is for, such as digest-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 a ConflictError.

Read a schedule#

schedules.retrieve takes a schedule or its ID, and returns the schedule with its next ticks and its newest decided ticks:

NodePythonValue
ididThe schedule. Each run's payload carries it as scheduleId.
typetypeDECLARATIVE for a declared schedule, IMPERATIVE for one created through the API.
task, cron, timezonetask, cron, timezoneWhat it runs, and when.
activeactiveFalse while paused.
externalId, deduplicationKeyexternal_id, deduplication_keyWhat a schedule was created with through the API. Null on a declared schedule.
environment, deploymentIdenvironment, deployment_idWhere it fires. deploymentId is the deployment that declares it, or null.
nextRunnext_runIts next tick. Null while paused.
lastTimestamp, lastRunIdlast_timestamp, last_run_idThe last tick that started a run, and that run.
upcomingupcomingThe next 5 ticks. Empty while paused. Only from retrieve.
ticksticksThe newest 20 decided ticks, newest first. Only from retrieve.

Each tick says what happened:

NodePythonValue
timestamptimestampThe tick.
outcomeoutcomefired or skipped.
runId, runStatusrun_id, run_statusThe run it started, and that run's status now.
reasonreasonWhy it was skipped. See When a schedule fires.
missedSincemissed_sinceSet when the tick stands for missed ticks too: the first of them.
decidedAtdecided_atWhen 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);
  • Numbered pages are the default, as in Trigger.dev: page from 1, and perPage (Python: per_page) from 1 to 200, default 50. The answer's pagination has currentPage, totalPages and count.
  • A cursor is the other way: pass limit (1 to 200) or cursor. The answer's nextCursor (Python: next_cursor) is the next page's cursor, or null on the last page.
  • task lists 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);
CallDeclared scheduleCreated through the API
deactivatePauses it. It stays paused across deploys.Pauses it.
activateResumes it.Resumes it.
updateConflictError: 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.
  • update replaces all four fields. A time zone you leave out goes back to UTC, 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#

Terminal
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:

JSON
{"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"]}
FieldValue
typeDECLARATIVE for a declared schedule, IMPERATIVE for one created through the API.
timestampThe tick this run is for. A run that starts late still gets its own tick.
lastTimestampThe last tick that started a run. Left out on the schedule's first run.
timezoneThe schedule's time zone.
scheduleIdThe schedule's ID.
externalIdThe schedule's external ID. Left out when it has none.
upcomingThe 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 };}

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 as schedule:6f1c2b8e-0d4a-4c1e-9f3b-2a7d5e8c9b10:2026-10-08T12:00:00Z. These keys are reserved: a trigger whose key starts with schedule: is a ValidationError.
  • In a run stream, the run's run.created event has the origin schedule.

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 lastTimestamp still 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 missedSince names the first missed one, and the run's lastTimestamp covers 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:

FieldValues
Minute0 to 59
Hour0 to 23
Day of month1 to 31
Month1 to 12, or JAN to DEC
Day of week0 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.

CronFires
*/15 * * * *Every 15 minutes
0 6,18 * * *At 06:00 and 18:00
0 9 * * MON-FRIAt 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, and L, W, #, ? and +
  • a step on a single number, such as 0/10 * * * *. Write */10 * * * * instead.
  • a range that runs backwards, such as MON-SUN or DEC-JAN
  • a stepped * in one day field while the other names days, such as 0 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 * * * and 0-5 2 * * * are fixed times. */15 * * * * and 0 * * * * 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/DenverMarch 8, 2026: 02:00 jumps to 03:00November 1, 2026: 01:00 to 02:00 happens twice
30 2 * * *Fires once, at 03:00Fires once, at 02:30
30 1 * * *Fires once, at 01:30Fires once, at the first 01:30
*/15 * * * *Skips 02:00 to 02:45Fires at both 01:00s, both 01:15s, and so on
0 * * * *Skips 02:00Fires 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.