Search code examples
node.jsagenda

node js - how to modify an existing job in agenda


I am creating a back-end application using node js and mongoDb and in that i am using agenda for job scheduling. I have offerModel in my application to add, update or delete offers. So, for updating the expired offers according to their validity, i am using job scheduling library agenda. Now if i am increasing the offer's validity, do i need to delete the corresponding job and again define it, or Is there a way to update an existing job?


Solution

  • AFAIK, you can't update the entry. You need to cancel and define the entry like:

    agenda.cancel({name: jobName}, function(err, numRemoved) {
        var jobName = 'job' + new Date().getTime();
    
        agenda.define(jobName, doSomething);
    });