0

I need a job scheduler that runs a couple of jobs in a specific time interval. So, I used agenda module for doing this task. What happens is when the server is restarted the jobs get executed and this happens for 4 times in regular interval basis and after that agenda stops working without throwing any error. I tried canceling the jobs and stopping agenda whenever the server stops. So that agendaJobs creates new collection every time the server is restarted. But still, I experience the same issue. Since, I have multiple node instances running, I need the jobs to run only once in that time interval. Hence, I used agenda. Is there any different schedulers which can do the same or am I doing something wrong?

var agenda = new Agenda({db: {address: mongoConnectionString}});
var startCron = function(server, callback){

agenda.define('job1', function(job, done) {
  job1.execute();
});

agenda.define('job2', function(job, done) {
  job2.execute();
});

agenda.define('job3', function(job, done) {
  job3.execute();
});

agenda.on('ready', function() {
    agenda.every('10 minutes', ['job1', 'job2',
        'job3']);
  agenda.start();
  console.log("Cron job setup completed.");
  callback(null, server);
});
}

// this is my kill process

var killProcess = function() {

    try {
        mongoose.disconnect();
        console.log(arguments);
        console.log("Connection got closed.");

    } catch (e) {
        console.log(e);
    }
    agenda.cancel({}, function(err, numRem){
        console.log("Cancelling Agenda Jobs", err, numRem);
        agenda.stop(function() {
            console.log("Stopping Agenda")
            setTimeout(function(){
                process.exit(1);
            }, 2000);
          });
    });
};
Ashish Shetty
  • 456
  • 1
  • 4
  • 8

0 Answers0