With the `scheduled` handler, what's the difference between waitUntil and just using async/await?
Is it necessary to use
waitUntil()
when I could just use good old async/await to delay termination of the worker?12 Replies
nope, i never waitUntil in scheduled. I always just await
Interesting, thank you. Cursor (your very helpful AI assistant) is telling me that there's a risk with async/await that workers will not wait, and may shut down before the promise is resolved. Presumably (and based on your reply) that's false? That would default the whole point of async/await.
AI is far too trusted.
Anyway, if you await and you aren't going over limits - it's fine. It will never not randomly wait. The only time waiting will be cancelled is if you go over the limits, which is expected.
Yeap makes sense, thanks. And just to clarify, limit on scheduled is 15 min, not the 30 secs available to HTTP, that right?
Depends on the schedule time iirc
Scheduled Workers (Cron Triggers) have different limits on CPU time based on the schedule interval. When the schedule interval is less than 1 hour, a Scheduled Worker may run for up to 30 seconds. When the schedule interval is more than 1 hour, a scheduled Worker may run for up to 15 minutes.Yeah, 30 seconds CPU time for let's say 1 min interval. 15 mins for let's say 1 hour interval.
Thank you. Does that rule apply to all CRONs culmulatively, or each individual CRON?
So if I have one CRON that runs every 30 mins, it'll be subject to a 30sec limit. If I have two CRONs, one that runs on 00 and one that runs on 30, each will get 15 mins, or is that wrong?
Well on 00/30 would be set times and would run hourly so yes, they'd get 15 mins
Schedule = * * * * *
Those invocations will have 30 seconds
schedule = 0 * * * *
Is run hourly so 15 mins
It's just schedule is hour+ = 15 mins CPU
schedule less = 30 seconds
Yeah - I was just doubting myself as it seems we can get round the 30sec limit just by having a second CRON, provided each individual CRON is not more frequent than hourly
No, doesn't get around it
If you have 2 schedules, the less than hour schedule is invoked with 30 seconds. Other with 15 mins
Just based on schedule
Sorry, I may be missing something here. My point is that if I have two schedules that each run no more than once an hour, but at different times OF the hour, they would each get 15 mins, right? Because individually they are not running more than once an hour. But the cumulative result is I still have "a" CRON firing once every 30 mins.
Yes but because they run every hour is why they get 15 mins
In this situation, the minutely invocation will have 30 seconds of CPU time. The hourly one will have 15 mins of CPU time.
It comes down to the schedule time of that invocation
Thank you, much appreciated.