Ask questionsStopping a cron after one-time execution

If I set a job to run once, do I need to do any cleanup? Like, do I need to call job.stop() at any point?

Here's my job:

  const date = new Date()

  date.setMinutes(date.getMinutes() + 5)

  const job = new CronJob(date, function () {
      // do stuff here


The job will run 5 minutes from now, which is what I want. Just curious if I NEED to call job.stop() at some point in the future


Answer questions ncb000gt

You don't need to do any cleanup if you specify a date object (Date/moment). But, if you specify a crown syntax you're hen you would need to use .stop(). The internal job uses setTimeout.

On Mon, Sep 14, 2020, 2:42 PM Matthias Baldi wrote:

I don't know if you have to call the stop() method. But why do you create not just a simple method with a setTimeout? would be do the same thing isn't it? In my understanding a cronjob is something which runs multiple times.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe .


Related questions

Something went wrong. cron reached maximum iterations hot 1
Github User Rank List