Skip to content
4th April 2025: This is a preview, whilst production-ready, it means some APIs might change

Cron Triggers

If you want to schedule a background task, Cloudflare supports Cron Triggers.

Setup

Within your wrangler.jsonc file, add a new section called triggers:

wrangler.jsonc
"triggers": {
"crons": ["* * * * *"]
}

Where crons includes an array of cron schedules.

Within your worker.tsx file, adjust your defineApp function:

const app = defineApp([
...
]);
export default {
fetch: app.fetch,
async scheduled(controller: ScheduledController) {
switch (controller.cron) {
// Runs every minute
case "* * * * *":
console.log("๐Ÿงน Clean up Unverified Users");
break;
}
console.log("โฐ cron processed");
},
} satisfies ExportedHandler<Env>;

Notice the case matches the cron schedule defined within the wrangler.jsonc file.

In the example above, console.log("๐Ÿงน Clean up Unverified Users"); runs every minute. However, you could account for different schedules by adding more triggers to your wrangler.jsonc file and more cases to your switch statement:

wrangler.jsonc
"crons": ["* * * * *", "0 0 * * *"]
worker.tsx
// Runs every hour
case "0 0 * * *":
console.log("๐Ÿ”„ Update something");
break;

Cloudflare Cron Triggers

Within the Cloudflare Dashboard UI, you can view all the cron triggers for your worker. Click on the Settings tab, and then click on the Cron Triggers section.

To view more details about the events, click on the View Events link.

You can see a list of all the events that have been triggered for your worker.

Further Reading