How can i stop cron trigger from worker's code?

Hi! I need a worker to execute scheduled events at few minutes interval for 1 - 2 days. But i dont want the worker to run everyday, i want to stop the worker or dezactivate/modify the cron trigger from code when a certain condition is met.

Does anyone know if this is possible?:slight_smile:

There’s no way to stop/modify the cron trigger within code easily, you’d have to use the CF API to change your Worker, or use something like KV/DOs/D1 to store information which you could check on each cron run if you should run or not. You’d have a fair few unnecessary invocations though.

Durable Object Alarms may be a better fit, although require you to use DOs: Alarms · Cloudflare Durable Objects docs, you can schedule them whenever you want, they retry, etc.

2 Likes

Thanks!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.