Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/cron-triggers/configuration.md
1# Cron Triggers Configuration23## wrangler.jsonc45```jsonc6{7"$schema": "./node_modules/wrangler/config-schema.json",8"name": "my-cron-worker",9"main": "src/index.ts",10"compatibility_date": "2025-01-01", // Use current date for new projects1112"triggers": {13"crons": [14"*/5 * * * *", // Every 5 minutes15"0 */2 * * *", // Every 2 hours16"0 9 * * MON-FRI", // Weekdays at 9am UTC17"0 2 1 * *" // Monthly on 1st at 2am UTC18]19}20}21```2223## Green Compute (Beta)2425Schedule crons during low-carbon periods for carbon-aware execution:2627```jsonc28{29"name": "eco-cron-worker",30"triggers": {31"crons": ["0 2 * * *"]32},33"placement": {34"mode": "smart" // Runs during low-carbon periods35}36}37```3839**Modes:**40- `"smart"` - Carbon-aware scheduling (may delay up to 24h for optimal window)41- Default (no placement config) - Standard scheduling (no delay)4243**How it works:**44- Cloudflare delays execution until grid carbon intensity is lower45- Maximum delay: 24 hours from scheduled time46- Ideal for batch jobs with flexible timing requirements4748**Use cases:**49- Nightly data processing and ETL pipelines50- Weekly/monthly report generation51- Database backups and maintenance52- Analytics aggregation53- ML model training5455**Not suitable for:**56- Time-sensitive operations (SLA requirements)57- User-facing features requiring immediate execution58- Real-time monitoring and alerting59- Compliance tasks with strict time windows6061## Environment-Specific Schedules6263```jsonc64{65"name": "my-cron-worker",66"triggers": {67"crons": ["0 */6 * * *"] // Prod: every 6 hours68},69"env": {70"staging": {71"triggers": {72"crons": ["*/15 * * * *"] // Staging: every 15min73}74},75"dev": {76"triggers": {77"crons": ["*/5 * * * *"] // Dev: every 5min78}79}80}81}82```8384## Schedule Format8586**Structure:** `minute hour day-of-month month day-of-week`8788**Special chars:** `*` (any), `,` (list), `-` (range), `/` (step), `L` (last), `W` (weekday), `#` (nth)8990## Managing Triggers9192**Remove all:** `"triggers": { "crons": [] }`93**Preserve existing:** Omit `"triggers"` field entirely9495## Deployment9697```bash98# Deploy with config crons99npx wrangler deploy100101# Deploy specific environment102npx wrangler deploy --env production103104# View deployments105npx wrangler deployments list106```107108**⚠️ Changes take up to 15 minutes to propagate globally**109110## API Management111112**Get triggers:**113```bash114curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/scripts/{script_name}/schedules" \115-H "Authorization: Bearer {api_token}"116```117118**Update triggers:**119```bash120curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/scripts/{script_name}/schedules" \121-H "Authorization: Bearer {api_token}" \122-H "Content-Type: application/json" \123-d '{"crons": ["*/5 * * * *", "0 2 * * *"]}'124```125126**Delete all:**127```bash128curl -X PUT "https://api.cloudflare.com/client/v4/accounts/{account_id}/workers/scripts/{script_name}/schedules" \129-H "Authorization: Bearer {api_token}" \130-H "Content-Type: application/json" \131-d '{"crons": []}'132```133134## Combining Multiple Workers135136For complex schedules, use multiple workers:137138```jsonc139// worker-frequent.jsonc140{141"name": "data-sync-frequent",142"triggers": { "crons": ["*/5 * * * *"] }143}144145// worker-daily.jsonc146{147"name": "reports-daily",148"triggers": { "crons": ["0 2 * * *"] },149"placement": { "mode": "smart" }150}151152// worker-weekly.jsonc153{154"name": "cleanup-weekly",155"triggers": { "crons": ["0 3 * * SUN"] }156}157```158159**Benefits:**160- Separate CPU limits per worker161- Independent error isolation162- Different Green Compute policies163- Easier to maintain and debug164165## Validation166167**Test cron syntax:**168- [crontab.guru](https://crontab.guru/) - Interactive validator169- Wrangler validates on deploy but won't catch logic errors170171**Common mistakes:**172- `0 0 * * *` runs daily at midnight UTC, not your local timezone173- `*/60 * * * *` is invalid (use `0 * * * *` for hourly)174- `0 2 31 * *` only runs on months with 31 days175176## See Also177178- [README.md](./README.md) - Overview, quick start179- [api.md](./api.md) - Handler implementation180- [patterns.md](./patterns.md) - Multi-cron routing examples181