-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobs.js
33 lines (26 loc) · 816 Bytes
/
jobs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var config = require('./config'),
Agenda = require('agenda'),
agenda = new Agenda(),
mongoose = require('mongoose'),
jobTypes = ["notifications","actions"];
//mongoose.connect('mongodb://'+config.mongodb.server+':'+config.mongodb.port+'/'+config.mongodb.database);
agenda.mongo(mongoose.connection.collection('agendaJobs').conn.db,'agendaJobs', function (err) {
console.log("error: "+err);
});
jobTypes.forEach(function(type) {
require('./jobs/' + type)(agenda, mongoose);
});
if (jobTypes.length > 0) {
agenda.start();
}
// Handles graceful stopping of jobs
function graceful() {
agenda.stop(function() {
mongoose.disconnect(function(err){
process.exit(0);
});
});
}
process.on('SIGTERM', graceful);
process.on('SIGINT' , graceful);
module.exports = agenda;