Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Agenda - create multiple job definitions with same name, different job config
// Create each job with the same name so we can control concurrency (the number of parallel jobs that can be run).
// Each job will have the same name, but different configs. Use the 'unique' method to prevent duplicates.
agenda.define('MyJob', {concurrency: 3}, loadData);
_.each(myJobs, function(job){
agenda.create('MyJob', job)
.unique({'job.name': job.name}, { insertOnly: true })
.repeatEvery('1 hour')
.save();
});
// Custom job fail logic
agenda.on('fail:MyJob', function(err,job) {
logger.info(job.attrs.data.name, " - Retrying job in 10 minutes");
job.attrs.nextRunAt = moment().add(10, 'minutes');
job.save();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.