Skip to content

Instantly share code, notes, and snippets.

@MiguelCedric
Created March 8, 2018 20:45
Show Gist options
  • Save MiguelCedric/1b82fb7ad95de3a3c9170d8d4dd7e51e to your computer and use it in GitHub Desktop.
Save MiguelCedric/1b82fb7ad95de3a3c9170d8d4dd7e51e to your computer and use it in GitHub Desktop.
Agenda Configuration
const Agenda = require('agenda');
const mongoConnectionString = 'mongodb://localhost:27017/yourdatabase';
// or override the default collection name:
let agenda = new Agenda({db: {address: mongoConnectionString, collection: 'jobs'}});
let jobTypes = process.env.JOB_TYPES ? process.env.JOB_TYPES.split(',') : [];
jobTypes.forEach(function(type) {
require('./jobs/' + type)(agenda);
});
if(jobTypes.length) {
agenda.on('ready', function() {
agenda.start();
});
}
function graceful() {
agenda.stop(function() {
process.exit(0);
});
}
process.on('SIGTERM', graceful);
process.on('SIGINT' , graceful);
module.exports = agenda;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment