skip to content

A Cloudflare Worker's ranking recompute ran fine on an hourly Cron Trigger but fails with exceededCpu after moving to every 30 minutes; why, and what fixes it?

level: seniorimportance: nice to knowfreq 22%

answer

  1. the code did not change
  2. the budget follows the schedule
  3. shorter than one hour
  4. local runs enforce no limits

basics

~20 s

On Workers Paid a Cron Trigger invocation gets 15 minutes of CPU when its schedule is hourly or rarer, but only 30 seconds when it fires more often. Restore the hourly schedule, cut the work below 30 seconds, or split it.

solid answer

~40 s

The CPU time a Cron Trigger invocation may use depends on how often it fires. On Workers Paid a schedule of one hour or longer gets 15 minutes of CPU per invocation, while one that fires more often than hourly gets 30 seconds; Workers Free gets 10 ms either way. A recompute that used around 45 seconds fit the hourly allowance and overruns the half-hourly one, so the outcome becomes `exceededCpu`. Wall time is separate, 15 minutes for any Cron Trigger run. `wrangler dev` cannot show this because limits are only enforced once deployed. Fixes: go back to hourly, make the recompute incremental, or have the cron only enqueue shards for a queue consumer or a Workflow to score.

go deeper

for a junior

Recall that Cron Trigger invocations have their own CPU and wall-time limits, and that exceededCpu means the CPU budget ran out.

for a middle

Explain that on Workers Paid the CPU allowance is 30 seconds for schedules shorter than an hour and 15 minutes for hourly or rarer ones.

for a senior

Diagnose from invocation logs rather than local runs, then pick a fix that matches the cause: restore the schedule, shrink the work or split it.

for a principal

Treat schedule changes as capacity changes: a team should know each periodic job's CPU headroom before agreeing to run it more often.

## The symptom A leaderboard API Worker rebuilds its rankings from a Cron Trigger. On `"0 * * * *"` the job ran cleanly for months, taking about 45 seconds of CPU time to score and sort every player. Product asked for fresher rankings, so the expression became `"*/30 * * * *"`. From the next run on, invocations fail: Workers Logs show the invocation outcome `exceededCpu`, and the rankings stop updating. Nothing else changed, the code passed review, and it still runs fine under `wrangler dev`. ## The limit that changed The CPU time a Cron Trigger invocation may use depends on the plan and on **how often the schedule fires**: | Plan | Schedule interval | CPU time per Cron Trigger invocation | |---|---|---| | Workers Free | any | 10 ms | | Workers Paid | shorter than 1 hour | 30 seconds | | Workers Paid | 1 hour or longer | 15 minutes | Wall time is a separate limit: every Cron Trigger invocation may run for at most 15 minutes of wall-clock time, whatever its schedule. So the hourly job had a 15-minute CPU allowance and used 45 seconds of it; the half-hourly job gets 30 seconds and runs out. The code is the same, the budget is not. ## Confirming the diagnosis 1. **Read the outcome.** In Workers Logs, filter to the Worker's scheduled invocations and check the outcome and the CPU time of each one. `exceededCpu` with CPU time near 30 seconds points straight at this limit. 2. **Compare with the old runs.** The hourly runs' CPU time shows how far over the new allowance the job is, which tells you whether a small optimisation could ever fit. 3. **Rule out wall time.** An invocation that hits the 15-minute wall-time limit looks different and is unrelated to the schedule change. 4. **Explain the local pass.** Limits are only enforced when a Worker is deployed to Cloudflare's network, not in local development, so `wrangler dev` and a manual call to `/cdn-cgi/local/scheduled` cannot reproduce the failure. ## Fixes, from cheapest - **Restore an hourly schedule** if the freshness gain was not worth it; the larger allowance returns with it. - **Make the recompute incremental.** Rank only the players whose scores changed since the last run instead of resorting everyone, which can bring the work under 30 seconds. - **Split the work.** Let the cron handler only enqueue shards of players, and let a queue consumer or a Workflow's steps do the scoring; each of those runs under its own limits, covered in their own lessons. - **Precompute on write.** Update a player's rank when a score arrives, so the scheduled job only tidies up. Whichever fix ships, keep watching the scheduled invocations' CPU time, because player growth moves the job toward the limit again. ## A checklist before changing a schedule - Pull the CPU time of the job's recent runs from Workers Logs and note the highest, not the average. - Look up the allowance for the new interval and plan, and keep clear headroom under it. - Check the account's Cron Trigger budget (5 on Workers Free, 250 on Workers Paid) if the change adds expressions. - Remember that a new or changed schedule can take up to 15 minutes to reach the whole network, so the first run under it may come later than expected. ## What the interviewer wants to hear - The candidate does not blame the code, which did not change, and looks at the platform's limits first. - They know the Cron Trigger CPU allowance is tied to the schedule interval on the Paid plan, and that wall time is a different, fixed limit. - They know local runs do not enforce limits, so a passing `wrangler dev` session proves nothing about CPU. - They propose a fix that matches the cause: bring the work under the allowance or move it somewhere with a different one, not merely retry. The general lesson is that on Workers a configuration change can change a limit. A schedule, a plan or a trigger type each carries its own budget, and a change to any of them deserves the same review as a code change.

  • Why did the same Cloudflare Worker pass under wrangler dev?
    Limits such as CPU time are only enforced when a Worker runs on Cloudflare's network, not in local development. A manual call to `/cdn-cgi/local/scheduled` runs the handler to completion even past 30 seconds of CPU, so CPU budgets have to be checked against deployed invocation logs.
  • Does the Cloudflare Cron Trigger wall-time limit also change with the schedule?
    No. Every Cron Trigger invocation may run for at most 15 minutes of wall-clock time, whatever its schedule. Only the CPU allowance on Workers Paid depends on the interval: 30 seconds below one hour, 15 minutes at one hour or more.
  • How would you keep a Cloudflare Worker's ranking job fresh every 30 minutes without hitting the limit?
    Keep each run under 30 seconds of CPU: rank only players whose scores changed, or have the cron handler enqueue shards and let a queue consumer or a Workflow do the scoring. Precomputing ranks as scores arrive also shrinks the scheduled work to a cleanup.

  • The job must have a bug, because the same code passed every hourly run.
  • Every Cron Trigger invocation on Workers Paid gets the same 15 minutes of CPU.
  • A passing run under wrangler dev proves the job fits its production CPU limit.
  • Raising the schedule's frequency cannot change any limit the Worker runs under.
  • Cron Trigger wall time drops to 30 seconds when a schedule runs every 30 minutes.

Assumes the Workers limits of 2026-10-10: on Workers Paid a Cron Trigger gets 30 seconds of CPU below a one-hour interval and 15 minutes at one hour or more.