Cron Triggers: run a Worker on a schedule
Cron Triggers (scheduled Workers)
What it is
A Cron Trigger tells Cloudflare to run a Worker on a timetable instead of waiting for someone to visit a web page. Every time the schedule comes round, Cloudflare calls a separate function in the script named scheduled(), rather than the usual fetch() that answers browser requests.
The schedule is written as a cron expression with five fields: minute, hour, day of month, month, and day of week. For example "0 8 * * 1-5" means 8:00 every weekday. In wrangler.toml it lives in a [triggers] block, such as crons = ["0 8 * * 1-5"], and you can also add or edit it in the dashboard under the Worker’s Settings, in the Triggers area (the wording may differ slightly).
One important detail: Cron Triggers always run on UTC time, not Brisbane time. Brisbane is UTC+10 with no daylight saving, so 8:00am Brisbane is 22:00 UTC the previous day, written as "0 22 * * *". Getting that wrong is the most common reason a scheduled job seems to fire at a strange hour.
Why it matters
Over the last few lessons you met KV, D1, and R2, which hold data. Cron Triggers are what let a Worker do work by itself while you are at the clinic: check whether your sites are up and write the result to D1, fetch a news feed each morning, clean out old files in R2, or build a daily summary page.
This is the Cloudflare-native way to do jobs you might otherwise run on a VPS with cron or on an outside service that has to stay awake. It sits on the same account as the Worker and its bindings, and on the free plan a small number of triggers per account is included.
Because a scheduled job runs with nobody watching, keep it simple and safe: have it write to its own storage, log what it did, and never let a learning job send messages to patients or change DNS.
On your account
This tutor (cloudflare-tutor on cloudflare.kosan.xyz) has no Cron Trigger. Its wrangler.toml has routes only and no [triggers] block, and worker.js has only a fetch() handler. New lessons arrive because a separate routine redeploys it, not because the Worker wakes itself. That stays true after today.
A heartbeat checker on kosan.xyz is the classic Cron Trigger shape: crons = ["*/15 * * * *"] runs scheduled() every 15 minutes, which fetches each of your sites, INSERTs a row into a D1 checks table, and a normal fetch() page lists the latest results. A morning digest would instead use one trigger such as "30 21 * * *" for 7:30am Brisbane.
The pattern is: one schedule per job, written in UTC, attached only to that job’s Worker. Nothing in this lesson adds, edits, or removes a trigger on any Worker in your account.
Do this yourself
These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.
- In the Cloudflare dashboard, open Workers & Pages and, read only, look at the Settings → Triggers area (the wording may differ slightly) of a few existing Workers to see which ones already have a Cron Trigger and what their UTC schedules are, then work out on paper what Brisbane time each one fires (add 10 hours). As a throwaway only, create a new Hello World Worker named tutor-cron-lesson, add a Cron Trigger of "*/5 * * * *" (every 5 minutes), wait for it to show a run in that Worker’s logs or trigger events, then delete that same tutor-cron-lesson Worker. Do not add, edit, or remove triggers on cloudflare-tutor, ainews, aiweekly, or any live app.