Agenda: Restart jobs on server restart/failure

Created on 16 Oct 2016  路  3Comments  路  Source: agenda/agenda

I know this topic has been discussed a lot but i cant manage to make it work.
Can someone post a clear example to explain how to achieve that functionality?

So to begin with,

I create the jobs dynamically. The user fills up a form to receive some alerts.

        agenda.define('Test ' + index, function(job, done) {
            doReport(user);
            done();
        });

        parseWhen(report.when, function (err, data) {
                var cronPattern = data.minute + ' '
                    + data.hour + ' '
                    + data.day_month + ' '
                    + data.month + ' '
                    + data.day_week + ' ';

                agenda.every(cronPattern, 'Test ' + index);
                agenda.start();
                console.log("Agenda initted");
        })

I make use of the graceful shut down as suggested in the documentation.

//Agenda configuration
var initAgenda = function () {
    user.User.findOne({'slack.id':'U25V31BML'}, function (err, user) {

    agenda = new Agenda();
    agenda.database('mongodb://***');
        agenda.processEvery('10 seconds');

        agenda.on('ready', function() {
            console.log('ready');
            agenda.start();
            for(var i = 0; i < user.reports.length; i++) {
                createJob(user.reports[i], user);
            }
        })
    });
}

Any suggestions?

Most helpful comment

+1

All 3 comments

+1

@mKontakis from the looks of it this should really be using the same job but with unique. Maybe that'll fix your issue?

If this isn't a problem anymore please consider closing the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhan-pt picture nhan-pt  路  4Comments

weeco picture weeco  路  4Comments

simison picture simison  路  5Comments

ruslanjur picture ruslanjur  路  4Comments

michelem09 picture michelem09  路  6Comments