CPU time limit ignored in paid worker
I have a worker which needs to perform a long task for about 2 minutes after the initial fetch request has been dealt with.
I'm using ctx.waitUntil, but after about 30 seconds it stops.
I've set CPU time limit to 300_000 ms (5 minutes), but it hasn't helped.
What am I missing?

11 Replies
waitUntil only extends 30 seconds, that's normal.
I'd recommend using Workflows, start a workflow and run your task there. It's what they're made for :)
Cloudflare Docs
Cloudflare Workflows
With Workflows, you can build applications that chain together multiple steps, automatically retry failed tasks,
and persist state for minutes, hours, or even weeks - with no infrastructure to manage.
so if I just use a normal while loop then I can get past 30 seconds? I don't need to respond to the user so I didn't technically need to use waitUntil
You don't need a while loop, you can just do whatever if you want to block the response
thanks, I'll give that a go and checkout workflows. Thanks for your help!
I'd recommend workflows though haha
I use the Nuxt framework so it's not immediately clear how I'd get access to that step function in my Nuxt event handlers
also does the worker exit if it detects idle time?
I have a wait loop and at the end of each loop I have:
your worker could wait for 24 hours if it wanted
we do not limit wall time
(note: your worker may stop executing any time after 30 seconds due to us updating the runtime on that particularly server the worker is running on but not a frequent occurrence)
I can't seem to get the loop to go past 2 iterations before the worker is silently killed. It doesn't continue on past the for loop or anything, just stops executing in the 2nd loop

and today after switching back to waitUntil I get:
IoContext timed out due to inactivity, waitUntil tasks were cancelled without completing.