Skip to content

Instantly share code, notes, and snippets.

@cmlewis
Created April 12, 2018 19:20
Show Gist options
  • Save cmlewis/96919b8f38e8a4b7ad26a2b5b6759726 to your computer and use it in GitHub Desktop.
Save cmlewis/96919b8f38e8a4b7ad26a2b5b6759726 to your computer and use it in GitHub Desktop.
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