One minute can be delivered twice, a little early, or never. How to write a scheduled() handler so that each job still runs once and on the minute it was due.
A Cloudflare Cron Trigger runs twice, starts a job a minute late or skips it because nothing in the platform promises exactly one event per minute, delivered on the minute. You recognise the problem by its outputs, since the logs stay calm: two identical emails or posts that belong to one minute, an hourly job that always starts about a minute after the hour, a daily task that is simply absent on some days. The cure is in the scheduled() handler, not in the cron expression. Claim each (minute, job) pair with one atomic insert before anything leaves the Worker, compute the minute by rounding scheduledTime, catch up the minutes that never arrived, and set the watchdog above the real gaps. We…
Read the full report on AISkills402: https://aiskills402.com/blog/cloudflare-cron-trigger-runs-twice-late-or-never?utm_source=devto&utm_medium=social
Top comments (0)