profile
viewpoint

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
  })

  job.start()

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

kelektiv/node-cron

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 notifications@github.com 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 https://github.com/kelektiv/node-cron/issues/525#issuecomment-692240355, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAPJFZVRXATS72SKEVVV2LSFZPYVANCNFSM4Q6XJZHA .

useful!

Related questions

Something went wrong. cron reached maximum iterations hot 1
source:https://uonfu.com/
Github User Rank List