TL;DR: Cron Triggers let you run Workers on a schedule for maintenance, reporting, data sync, and cleanup tasks. This guide covers Cron Trigger configuration, the
scheduledevent handler, D1 backup automation, and monitoring scheduled executions. Automation patterns at tanstackship.com.
Introduction
Most applications need background jobs: daily database backups, weekly report generation, hourly data synchronization, or periodic cleanup. In Workers, Cron Triggers provide this capability with standard cron syntax. If you're new to the Workers platform, our Cloudflare Workers Introduction covers the fundamentals.
Cron Trigger Configuration
# wrangler.jsonc
{
"triggers": {
"crons": [
"0 0 * * *", # Daily at midnight
"*/30 * * * *" # Every 30 minutes
]
}
}
Scheduled Event Handler
export default {
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
switch (event.cron) {
case '0 0 * * *':
await runDailyDatabaseBackup(env)
await sendDailySummaryReport(env)
break
case '*/30 * * * *':
await syncStripeData(env)
await cleanExpiredSessions(env)
break
}
},
}
Common Cron Use Cases
| Cron Expression | Frequency | Typical Task |
|---|---|---|
0 * * * * | Every hour | Sync external data |
0 0 * * * | Daily | Database backup, report |
0 0 * * 0 | Weekly | Billing, cleanup |
0 0 1 * * | Monthly | Invoice generation |
*/15 * * * * | Every 15 minutes | Email queue processing |
Conclusion
Cron Triggers bring reliable background job processing to the Workers platform. Use them for maintenance, reporting, and data synchronization tasks that don't need user-initiated execution.
For database backup automation, see our Cloudflare D1 Backup Strategies guide, and the broader SaaS Data Backup and Recovery for comprehensive disaster planning. For asynchronous task queuing beyond scheduled triggers, explore the Cloudflare Workers Queues Guide for event-driven processing patterns.