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
Walshy
Walshy3w ago
nope, i never waitUntil in scheduled. I always just await
Mitya
MityaOP3w ago
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.
Walshy
Walshy3w ago
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.
Mitya
MityaOP3w ago
Yeap makes sense, thanks. And just to clarify, limit on scheduled is 15 min, not the 30 secs available to HTTP, that right?
Walshy
Walshy3w ago
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.
Mitya
MityaOP3w ago
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?
Walshy
Walshy3w ago
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
Mitya
MityaOP3w ago
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
Walshy
Walshy3w ago
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
Mitya
MityaOP3w ago
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.
Walshy
Walshy3w ago
Yes but because they run every hour is why they get 15 mins
schedules = [
"* * * * *",
"0 * * * *"
]
schedules = [
"* * * * *",
"0 * * * *"
]
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
Mitya
MityaOP3w ago
Thank you, much appreciated.

Did you find this page helpful?