Cloudflare Workers Cron Triggers: UTC Syntax, L/W/# Modifiers, and Multi-Cron Routing
Configure wrangler.jsonc triggers.crons in UTC, dispatch multiple schedules cleanly via controller.cron in scheduled(), and protect async tasks with ctx.waitUntil.
Incident Symptom & Protocol Root Cause
Production Failure Symptom
A Cloudflare Worker scheduled() handler terminates mid-flight before finishing database/API writes, all configured cron expressions execute the exact same code path because event.cron isn't switched, or deploying a cron with a timezone prefix fails Wrangler validation.
Scheduler Parser & Clock Mechanics
Cloudflare Workers evaluates all Cron Triggers strictly in UTC (supporting 5 fields plus Quartz-like L, W, and # day modifiers), invokes a single exported async scheduled(controller, env, ctx) entrypoint for every trigger on the Worker, and may cancel unawaited promises unless passed to ctx.waitUntil(...) or awaited directly.
Broken vs Verified Configuration
// wrangler.jsonc:
// { "triggers": { "crons": ["*/5 * * * *", "0 2 * * *"] } }
export default {
// BUG 1: Both */5 and 0 2 run heavyNightlyCleanup() every 5 minutes!
// BUG 2: Floating unawaited promise gets killed as soon as scheduled() returns!
scheduled(controller: ScheduledController, env: Env, ctx: ExecutionContext) {
syncFastMetrics(env);
heavyNightlyCleanup(env);
},
};// wrangler.jsonc
// {
// "triggers": {
// "crons": ["*/5 * * * *", "0 2 * * *", "55 23 L * *"]
// }
// }
export default {
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext
): Promise<void> {
switch (controller.cron) {
case "*/5 * * * *":
ctx.waitUntil(syncFastMetrics(env, controller.scheduledTime));
break;
case "0 2 * * *":
ctx.waitUntil(heavyNightlyCleanup(env));
break;
case "55 23 L * *":
ctx.waitUntil(closeMonthlyUsage(env));
break;
default:
throw new Error(`Unhandled cron expression: ${controller.cron}`);
}
},
};Operational Deep Dive
Cloudflare Workers Cron Triggers execute on Cloudflare's edge control plane at zero idle cost, invoking your Worker's scheduled(controller, env, ctx) handler with controller.cron (the exact string from wrangler.jsonc) and controller.scheduledTime (the nominal Unix epoch millisecond timestamp of the tick). Switching on controller.cron lets one Worker host multiple distinct schedules—such as a 5-minute health check, a nightly purge, and a month-end billing rollup—without deploying separate Worker services.
Note two syntax differences between Cloudflare Workers Cron Triggers and AWS EventBridge: Workers typically use 5 fields (minute, hour, day-of-month, month, day-of-week) ALWAYS evaluated in UTC, yet unlike strict POSIX cron, Cloudflare's parser DOES support L (last day of month or week, such as 55 23 L * *), W (nearest weekday, such as 0 9 15W * *), and # (Nth weekday of month, such as 0 9 * * 2#1 or MON#1) without requiring a 6th Year field!
When testing locally with npx wrangler dev --test-scheduled, Wrangler exposes a local HTTP endpoint: run curl 'http://127.0.0.1:8787/__scheduled?cron=*+*+*+*+*' to trigger specific controller.cron branches deterministically on localhost before deploying. Keep in mind that Cron Trigger propagation across Cloudflare's global network can take up to 15 minutes after wrangler deploy.
Cloudflare Workers Cron Triggers Operational Reference
| Engine / Case | Runtime Behavior | Production Remediation |
|---|---|---|
| Timezone evaluation | 100% UTC only; no timezone property exists in wrangler.jsonc triggers.crons. | Keep schedules in UTC, or run hourly (0 * * * *) and check Intl.DateTimeFormat local hour inside JS for DST-sensitive tasks. |
| Multiple crons in triggers.crons | Every cron invokes the same scheduled(controller, env, ctx) export. | Switch strictly on controller.cron (must match wrangler.jsonc string character-for-character). |
| Local testing in wrangler dev | Crons do not fire automatically unless triggered or --test-scheduled is enabled. | Run wrangler dev --test-scheduled and curl 'http://127.0.0.1:8787/__scheduled?cron=0+2+*+*+*'. |
| Execution & wall-clock limits | Unawaited async I/O terminates when scheduled() returns unless registered with ctx.waitUntil(). | Always await tasks or wrap in ctx.waitUntil(promise); offload multi-step durable jobs to Workflows/Queues. |
Edge Cases & Engineering FAQs
How do I run a Cloudflare Worker at 09:00 America/New_York year-round across DST if Workers Cron is UTC-only?
Configure triggers.crons to fire at BOTH candidate UTC hours ("0 13,14 * * 1-5" — 13:00 UTC is 09:00 EDT; 14:00 UTC is 09:00 EST) and at the first line of scheduled() verify the current local hour via new Intl.DateTimeFormat('en-US', { timeZone: 'America/New_York', hour: 'numeric', hour12: false }).format(new Date(controller.scheduledTime)) === '09'!
How many Cron Triggers can a single Cloudflare Worker have?
Check account plan quotas: Free plans allow up to 5 Cron Triggers across the account (3 per Worker historically, check current Workers limits), while Workers Paid plans dramatically raise trigger and CPU ceilings (up to 15 minutes CPU time for Cron Triggers >=15m apart).
Why did renaming '0/15 * * * *' in wrangler.jsonc break my switch(controller.cron) statement?
controller.cron passes the literal expression string configured in triggers.crons. Define shared constant strings or normalize whitespace so wrangler.jsonc and TypeScript switch cases never drift.
Runtime Dead-Man's-Switch Verification
Dead-man's-switch heartbeat checks that page on-call when a scheduled job skips a DST gap, stalls on a lock, or exits non-zero.