Skip to content

Cron Triggers

A Cron Trigger runs a Worker’s scheduled handler on a schedule. workerd keeps each Worker’s schedule in a Durable Object whose alarm calls the handler, so a cluster runs each occurrence on one instance. Read the Cloudflare Cron Triggers documentation for the API.

Example

The Cron Trigger example logs the scheduled time once a minute.

index.jsjs
export default {
  async fetch(request, env) {
    return new Response("The cron runs once a minute.\n");
  },
  async scheduled(controller, env, ctx) {
    console.log("cron", controller.scheduledTime);
  },
};
wrangler.jsoncjsonc
{
  "name": "cron",
  "main": "index.js",
  "compatibility_date": "2026-01-01",
  "no_bundle": true,
  "triggers": { "crons": ["* * * * *"] }
}

Cron Triggers are experimental, so they need --experimental:

npx workerd serve --experimental ./cron/wrangler.jsonc

At the start of each minute, workerd prints a line such as cron 1795555260000, the scheduled time in milliseconds.

Schedules

A project declares its schedules in a triggers.crons array. workerd reads the Cloudflare cron dialect, in UTC:

When both day fields are restricted, a day matches when one of them matches. An expression that workerd cannot parse stops startup.

Differences from Cloudflare

  • workerd refuses a descending range such as SAT-SUN, a list that contains * such as 1,*, and an expression that never matches.
  • A handler that throws runs again 2 seconds later. The delay doubles after each failure, for up to six retries. A retry keeps the scheduledTime of its occurrence. If the next occurrence comes before a pending retry, it replaces the retry. controller.noRetry() stops the retries.
  • The runs of one Worker never overlap. workerd skips an occurrence if a handler still runs at its time. A run that takes longer than 10 minutes counts as a failure.
  • After downtime, workerd runs the first missed occurrence once and skips the others.

See also Cloudflare compatibility.

Type to search…

↑↓ navigate↵ selectEsc close