What this thread does
Do first: implement scheduled() and define triggers.crons in Wrangler; express the schedule in UTC (Cron Triggers).
Short answer
Use Cron Triggers for periodic execution, Preview settings with separate resources for deployment checks, and encrypted secret bindings for credentials (cron, Previews, secrets). Add an account-wide spending limit for Workers usage, while allowing for enforcement delay and separate product charges (spending limits).
Choose / don't choose
- Preview: use for isolated changes; Cron Triggers do not invoke its scheduled handler, so do not use its timer behavior as production evidence (Preview guide).
- Spending limit: use when stopping every Worker in the account is acceptable; it is not an exact maximum bill (limits).
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
triggers.crons | Example: ["0 15 1 * *"], first day of each month at 15:00 UTC | Wrangler Cron Trigger configuration | Cron |
previews | Separate Preview settings; use separate mutable resources | Worker Previews | Guide |
| Secret binding | Encrypted sensitive value rather than plaintext configuration | Worker credentials | Secrets |
| Spending limit | User-selected request and CPU usage threshold after included usage | Whole Workers account; subscription excluded | Limits |
Order of operations
1. Add the scheduled handler and cron configuration (Cron). 2. Invoke the handler locally through /cdn-cgi/local/scheduled on the development server's port (handler reference). 3. Configure separate Preview resources before npx wrangler preview. Preview URLs are public by default; apply Access for private content (Preview guide). 4. Choose secret deployment behavior deliberately: wrangler secret put deploys immediately; wrangler versions secret put creates a version for later deployment (secrets). 5. Configure the spending threshold after accounting for the outage tradeoff and separate product charges (limits).
Known failures and fixes
| Symptom | Cause | Fix | Source |
|---|---|---|---|
| Preview timer never fires | Cron Triggers do not invoke Preview scheduled handlers | Exercise scheduled logic through the local invocation route | Preview, handler |
| All Workers stop accepting invocations | Account spending threshold takes effect | Check Billing > Spend Management; raise or remove the limit to resume | Limits |
| Removing cron configuration leaves an old timer | Omitted cron configuration preserves deployed triggers | Set crons to an empty array to remove all triggers | Cron |
Missing
- What exact threshold fits this job? No workload volume or budget is supplied.
- How should retries and duplicate runs affect application state? These references do not supply this job's transaction design.
- How can the entire bill be capped exactly? Workers limits exclude other product charges and enforcement can lag (limits).
Checked
2026-11-23; sources read:
Started from a post by @WhatWorks editors, packaged by the editor.