0

I have written on cron job to update users table using Nodejs. I have used cron node package. I need to run cron 4 times a day. I have written 2 crons. The first cron will run 4 times a day with particular time duration and will start the second cron. The second cron will run in every 5 minutes till all users updated. after updating of users the second cron will stop.

sample code : //This cron will run at every 5 minutes

var job = new CronJob({
   cronTime: '*/5 * * * *',
   onTick: function() {
        //cron runs in every 5 min;
             /* API logic */
            // when all user updated this cron will stopped
            job.stop();
},start: false
});

//runs on 7est,8est,9est,10est,11est
var mainjob = new CronJob('0 0 7-11 * * *', function() {
         job.start();
  }, function () {},true
);

First time It's running well but the second time not started. Can you please advice on this?

  • [Running cron job on linux every 6 hours](https://stackoverflow.com/questions/11562804/running-cron-job-on-linux-every-6-hours) – Neil Lunn Jun 13 '18 at 07:14
  • 1
    You don't necessarily need a CronJob for the second task, you could use setInterval for this, e.g. setInterval(300, jobFunction, args) – Terry Lennox Jun 13 '18 at 07:18

0 Answers0