Cloudflare Workers cron triggers are a crons array under triggers in your Wrangler config, plus a scheduled() handler in the same Worker. Every schedule runs in UTC and calls that one handler, which branches on controller.cron. Two details are easy to get wrong: weekday 1 means Sunday, not Monday, and the cron string must match your config exactly.
How do you add a cron trigger to a Cloudflare Worker?
Two pieces. The schedule lives in config, and the code lives in a scheduled export. This is a complete wrangler.jsonc for a Worker with two jobs: a sync every fifteen minutes and a weekly clean-up.
{
"name": "scheduled-jobs",
"main": "src/index.ts",
"compatibility_date": "2026-11-01",
"triggers": {
// UTC. Use day names: in Cloudflare's syntax 1 is Sunday.
"crons": ["*/15 * * * *", "0 3 * * MON"]
},
"vars": { "SOURCE_URL": "https://example.com/" },
"kv_namespaces": [{ "binding": "STATE", "id": "replace-with-your-namespace-id" }]
}
The Cron Triggers docs show the same block in TOML as [triggers] with crons = [ ... ], and you can scope a schedule to one environment with env.<name>.triggers. If staging and production run the same schedule against the same data, every job runs twice, so we give staging its own crons or crons = [].
The handler is a normal export on the default object. Here is the Worker that goes with that config:
interface Env {
STATE: KVNamespace;
SOURCE_URL: string;
}
// Must match wrangler.jsonc character for character.
const EVERY_15_MINUTES = "*/15 * * * *";
const MONDAY_3AM_UTC = "0 3 * * MON";
const FIFTEEN_MINUTES = 15 * 60 * 1000;
async function syncWindow(env: Env, from: Date, to: Date): Promise<void> {
const url = new URL(env.SOURCE_URL);
url.searchParams.set("updated_after", from.toISOString());
url.searchParams.set("updated_before", to.toISOString());
const res = await fetch(url);
if (!res.ok) throw new Error(`Source returned ${res.status}`);
await env.STATE.put("last-sync", to.toISOString());
}
async function pruneTempKeys(env: Env): Promise<number> {
let deleted = 0;
let cursor: string | undefined;
do {
const page = await env.STATE.list({ prefix: "tmp:", cursor });
await Promise.all(page.keys.map((k) => env.STATE.delete(k.name)));
deleted += page.keys.length;
cursor = page.list_complete ? undefined : page.cursor;
} while (cursor);
return deleted;
}
export default {
async scheduled(controller, env) {
// The slot this run belongs to, not the moment it happened to start.
const slot = new Date(controller.scheduledTime);
switch (controller.cron) {
case EVERY_15_MINUTES:
await syncWindow(env, new Date(slot.getTime() - FIFTEEN_MINUTES), slot);
break;
case MONDAY_3AM_UTC: {
const deleted = await pruneTempKeys(env);
console.log(`Pruned ${deleted} temp keys for ${slot.toISOString()}`);
break;
}
default:
// A typo in config will not fix itself on a second attempt.
controller.noRetry();
throw new Error(`No job for cron "${controller.cron}"`);
}
},
} satisfies ExportedHandler<Env>;
That code type-checks against @cloudflare/workers-types with strict on. ScheduledController gives you three things: cron, scheduledTime (milliseconds since the epoch) and noRetry(). The scheduled handler reference also documents ctx.waitUntil(), which you only need for background work that should not hold up the returned promise.
Why does a Monday cron run on Sunday?
Because Cloudflare numbers weekdays 1 to 7 with 1 as Sunday. In Linux crontab and GitHub Actions, 0 is Sunday and 1 is Monday, so 0 3 * * 1 reads as Monday to most developers. Paste it into a Worker and it runs on Sunday. Correct it to 2 and it works, until someone copies the line into a crontab and gets Tuesday.
The docs suggest the fix we use: write the day as a name. MON, fri and so on are accepted case-insensitively, and month names (JAN, aug) work too. Nobody misreads MON.
The same table lists the Quartz-style extras that Cloudflare supports. L and W work in the day-of-month field, so 59 23 LW * * runs at 23:59 on the last weekday of the month. L and # work in the weekday field, so 0 18 * * 6L is the last Friday of the month. Again, 6 is Friday because 1 is Sunday.
Then there is the clock. Cron triggers run in UTC with no timezone setting. A job meant for 3am in London runs at 3am GMT in winter and 4am BST in summer. If the hour matters to a person, schedule it in UTC and accept the drift, or schedule hourly and check the local time in code with Intl.DateTimeFormat and a timeZone option.
Why does controller.cron not match the switch case?
controller.cron holds the exact expression from your config, and the handler docs say the match is exact, spacing included. "*/15 * * * *" with a double space is a different string from "*/15 * * * *". So is "0 3 * * mon" against a case "0 3 * * MON".
So the example keeps each expression in a named constant with a comment pointing at the config, and its default branch throws instead of falling through. Without that branch, a schedule edited in wrangler.jsonc but not in code runs on time, reports success and does nothing. The throw turns it into a failed event you can see.
Before throwing it calls controller.noRetry(). As of November 2026 the Cloudflare docs list that method without spelling out a retry policy for scheduled events, so we do not rely on retries in either direction. A config mismatch is permanent, though, and we would rather say so explicitly.
How do you test a cron trigger locally?
wrangler dev does not fire your schedules on its own. The docs are explicit that local development does not run cron triggers automatically. You fire them by hand with an HTTP request to the dev server:
npx wrangler dev
# in another terminal: spaces in the expression become +
curl "http://localhost:8787/cdn-cgi/local/scheduled?cron=*/15+*+*+*+*&format=json&time=1763200800000"
# {"outcome":"ok","noRetry":false}
curl "http://localhost:8787/cdn-cgi/local/scheduled?cron=0+3+*+*+2&format=json"
# {"outcome":"exception","noRetry":true}
The second request is the numbered-weekday version of the Monday job, caught by the default branch. format=json returns the outcome and the noRetry flag instead of plain text. time sets controller.scheduledTime, which matters for any job that computes a window from it. Leave it out and you get the current time, so the window moves every run and the bug you are chasing never quite reproduces.
The same page describes a Local Explorer UI for this, which needs Wrangler 4.139.0 or later (or the Cloudflare Vite plugin 1.60.0 or later). The curl route is easier to script into a test.
Why use scheduledTime instead of Date.now()?
scheduledTime is when the run was due. Date.now() is when your code happened to execute. For a sync that asks an API for “everything updated in the last fifteen minutes”, the difference decides whether you get gaps and overlaps.
Compute the window from scheduledTime and each run covers the same fixed slot: 10:00 to 10:15, then 10:15 to 10:30. Rerun the 10:15 slot by hand, with time= locally, and you get identical inputs. Use Date.now() and the windows drift with start-up time, and a manual rerun covers a slot nobody asked for.
The same rule makes jobs safe to run twice. The docs make no promise about exactly-once delivery, so write each job so that a second run for the same slot changes nothing: upsert instead of insert, key records by slot.
What are the cron trigger limits?
From the Workers limits page, as of November 2026:
- 5 cron triggers per account on the Free plan, 250 on Paid.
- CPU time per run is 10 ms on Free. On Paid it is 30 seconds for schedules more frequent than hourly and 15 minutes for hourly or less frequent ones.
- Wall-clock time is capped at 15 minutes per invocation.
- Subrequests per invocation are 50 on Free and 10,000 by default on Paid.
Read the Free CPU figure twice. 10 ms covers sending a request and writing a KV value. Parsing and reshaping a large payload can go past it, and a run that exceeds its CPU limit is stopped, not slowed.
The per-account count also matters if you run one Worker per client or per environment. Two schedules across five Workers is already ten.
Why did a cron trigger not run after a deploy?
Changes to triggers take up to 15 minutes to propagate, and scheduled runs can be missed until they do. The trigger then starts at the next scheduled time. If a monthly invoice job is due at 00:00 on the 1st, do not deploy a schedule change at 23:55 on the 31st.
On deploy, the crons array replaces whatever triggers the Worker had. An empty array, crons = [], removes them all. Leaving triggers or crons out of the file entirely does not remove anything: the existing triggers stay. So deleting the block to “turn off” a job leaves it running, and anything added in the dashboard is wiped the next time someone deploys a config that does list crons. We keep schedules in the config file only.
For history, the dashboard keeps the 100 most recent cron events under the Worker’s settings. Anything older needs Workers Logs or the GraphQL Analytics API.
When should you not use a cron trigger?
Use cron for short, idempotent jobs on a fixed clock: syncs, clean-ups, cache warming, a daily digest. Keep the handler thin.
When a job can outgrow 15 minutes, needs retries with backoff, or fans out into thousands of items, make the cron a starter, not the worker. Have it enqueue messages or kick off a durable run, and let something built for failure do the work. Our posts on Cloudflare Queues retries and Cloudflare Workflows cover those two options, and if you are still deciding where the Worker lives at all, start with our Pages vs Workers comparison.
Scheduled jobs on Workers are a regular part of the serverless development work we do, usually as the thin trigger in front of a queue or a workflow.