How to start or stop CRON jobs programatically
I have this job that decreases a value in my database every second by one. But I don't want it to be alive forever basically. I want it to start its work when i want to and stop its work when i want to. How can i do that. Here is the CRON file and associated code.
1 Reply
There are two ways to do this, depending on how you're thinking about the job:
1. you can let the cron job keep running, but it detects when it should no-op. e.g. by reading from a special killswitch table. 2. you can run the mutation directly, and it schedules itself if it wants to keep going, with
if (keepGoing) { ctx.scheduler.runAfter(1000, api.crons.decrement) }