In Cloudflare Workers, how do Cron Triggers in triggers.crons invoke a scheduled() handler, and how does one handler serve several schedules?
answer
- no HTTP request involved
- the clock is UTC
- the controller names what fired
- match the exact expression string
basics
~10 sEach expression in triggers.crons fires on UTC and calls the Worker's scheduled(controller, env, ctx) handler. One handler serves every schedule, so it branches on controller.cron, the exact expression string that fired.
solid answer
~40 sCron Triggers are cron expressions listed under `triggers.crons` in the Wrangler file; when one matches, on UTC, Cloudflare invokes the Worker's `scheduled(controller, env, ctx)` handler with no HTTP request involved. `controller.cron` holds the exact expression that fired and `controller.scheduledTime` the scheduled time in milliseconds. Every schedule calls the same handler, so a Worker that rebuilds rankings hourly and sends a heartbeat every 15 minutes switches on `controller.cron`. The runtime waits for the handler's returned promise up to the 15-minute limit. Each deploy replaces the old schedules; `"crons": []` removes them, while omitting the key leaves them running. Changes take up to 15 minutes to propagate, and locally you fire the handler through `/cdn-cgi/local/scheduled`.
code
json · 7 lines{
"name": "leaderboard-api",
"main": "src/index.js",
"compatibility_date": "2026-10-10",
"kv_namespaces": [{ "binding": "RANKINGS", "id": "<KV_NAMESPACE_ID>" }],
"triggers": { "crons": ["0 * * * *", "*/15 * * * *"] }
}go deeper
Recall where the schedule lives, triggers.crons in the Wrangler file, that it runs on UTC, and that it calls scheduled(controller, env, ctx).
Explain branching on controller.cron, why scheduledTime cannot replace it, and how a deploy replaces, keeps or removes the existing schedules.
Show operational care: allow for the propagation delay, remove triggers with an empty array, and check Cron Events or Workers Logs when a run misbehaves.
Weigh the account-wide trigger budget and the CPU allowance per schedule when deciding how many periodic jobs a team runs this way.
## From expression to invocation A **Cron Trigger** maps a cron expression to a Worker. When the expression matches, Cloudflare invokes the Worker's `scheduled()` handler; there is no HTTP request involved. For a Worker managed with Wrangler, the expressions live in the Wrangler file under `triggers.crons`, an array of strings: ```json { "triggers": { "crons": ["0 * * * *", "*/15 * * * *"] } } ``` Key facts about the expressions: - They run on **UTC**, never on the local time of a user or a data center. - They have five fields: minute, hour, day of month, month and weekday. - Extended cron characters work too, such as `L` (last), `W` (weekday) and `#` (nth weekday of the month). - **Weekdays run from 1 = Sunday to 7 = Saturday**, unlike systems where 0 is Sunday; writing `SUN` or `MON` avoids the confusion. Cloudflare runs scheduled invocations on underused machines in its network, and an account can opt into Green Compute so that they run only in data centers powered by renewable energy. ## What the handler receives The handler signature mirrors `fetch`: `scheduled(controller, env, ctx)`. | Parameter | Carries | |---|---| | `controller.cron` | The exact expression string that fired, such as `"0 * * * *"` | | `controller.scheduledTime` | When the run was scheduled, in milliseconds since the epoch | | `env` | The same bindings the fetch handler sees | | `ctx` | The context, with `ctx.waitUntil()` | The runtime waits for the promise that `scheduled()` returns, up to the 15-minute wall-time limit of a Cron Trigger invocation, so an `await` is enough for one task. `ctx.waitUntil()` helps when several tasks run concurrently, and the first `waitUntil()` promise to fail is recorded as the run's status in the Cron Events history. ## One handler, several schedules A Worker has a single `scheduled()` handler, and every Cron Trigger invokes it. To run different work per schedule, branch on `controller.cron`, which must match the configured string character for character, spaces included. `controller.scheduledTime` cannot replace it: `0 * * * *` and `*/15 * * * *` both match at the top of every hour, so the time alone does not say which expression fired. ## Deploying, changing and removing schedules 1. **Replace, not merge.** Each Wrangler deploy replaces the Worker's previous Cron Triggers with the ones in the file. 2. **Remove with an empty array.** `"crons": []` removes them all; leaving out `triggers` or `crons`, or commenting the key out, leaves the deployed schedules in place. 3. **Allow propagation.** Adding, changing or deleting a Cron Trigger can take up to 15 minutes to reach the whole network. 4. **Per environment.** A `triggers` block inside a Wrangler environment gives that environment its own schedules. Limits are per account: 5 Cron Triggers on Workers Free and 250 on Workers Paid, across all Workers. The old cap of 3 per Worker was removed in October 2023. CPU time per invocation is 10 ms on Free; on Paid it is 30 seconds for schedules that fire more often than hourly and 15 minutes for hourly or rarer ones. ## Dashboard edits and other schedulers If a Worker is managed with Wrangler, Cloudflare's guidance is to manage its Cron Triggers only through the Wrangler file. A schedule added by hand in the dashboard (**Settings** > **Triggers** > **Cron Triggers**) is replaced the next time a deploy writes a `crons` array, so a hotfix made there quietly disappears. Keep the file the single source of truth, review schedule changes like code changes, and deploy them through the same pipeline. Workflows can also be started on a cron schedule through their own binding configuration; when the scheduled job is a multi-step process that needs retries per step, that lesson is the better fit than a large `scheduled()` handler. ## Testing and watching `wrangler dev` does not fire Cron Triggers on its own. Call the local route instead: `curl "http://localhost:8787/cdn-cgi/local/scheduled?cron=0+*+*+*+*"` runs the handler with that `controller.cron`, `&time=` overrides `controller.scheduledTime`, and `?format=json` returns a result such as `{"outcome":"ok","noRetry":false}`. In production, the Cron Events view in the dashboard keeps the 100 most recent runs, and Workers Logs keeps invocation logs for longer, with filtering. A good middle-level answer covers where the schedule is declared, UTC, the handler's `controller`, branching on `controller.cron`, and how to remove a trigger without leaving a stale one running.
- How do you test a Cloudflare Worker's scheduled() handler with wrangler dev?`wrangler dev` does not fire Cron Triggers on its own, so call `/cdn-cgi/local/scheduled` on the dev server. Add `?cron=0+*+*+*+*` to set `controller.cron`, `&time=` to set `controller.scheduledTime`, and `?format=json` to get the outcome back as JSON.
- How many Cron Triggers can a Cloudflare account have?Five on Workers Free and 250 on Workers Paid, counted across all the account's Workers. There is no separate per-Worker cap since the limit of 3 per Worker was removed in October 2023.
- Cron Triggers run on the time zone of the Cloudflare location that runs them.
- Each cron expression needs its own exported handler function.
- Deleting the triggers block from the Wrangler file removes the deployed schedules.
- In a Workers cron expression, weekday 1 means Monday.
- controller.scheduledTime is enough to tell which of two schedules fired.
- A scheduled() handler must wrap its work in ctx.waitUntil() or the runtime ignores it.
As of 2026-10-10 Cron Triggers are limited per account (5 Free, 250 Paid); the former cap of 3 per Worker was removed in October 2023.