Cron Triggers & Scheduled Workers
Run Cloudflare Workers on a schedule with Cron Triggers to automate recurring background tasks at the edge.
Why Scheduled Workers?
Beyond responding to HTTP requests, Workers can run on a schedule using Cron Triggers.
This is perfect for recurring jobs such as:
- Cleaning up stale data in KV or D1
- Sending daily report emails
- Refreshing cached API responses
- Aggregating analytics
No always-on server required, the Worker simply wakes up, runs, and goes back to sleep.
The scheduled() Handler
A scheduled Worker exports a scheduled() handler instead of (or alongside) fetch().
Cloudflare invokes it automatically at the times you define in cron expressions.
export default {
async scheduled(event, env, ctx) {
console.log('Triggered at: ' + event.scheduledTime);
}
};All lessons in this course
- WebSockets & Real-time
- Queues & Asynchronous Tasks
- Service Bindings & Integrations
- Cron Triggers & Scheduled Workers