forked from Trustroots/trustroots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
46 lines (39 loc) · 869 Bytes
/
worker.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
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
/**
* Trustroots
*
* Worker main entry file
*/
var async = require('async'),
mongooseService = require('./config/lib/mongoose'),
worker = require('./config/lib/worker');
async.waterfall([
// Bootstrap db connection
function (done) {
mongooseService.connect(function () {
done();
});
},
// Load models
function (done) {
mongooseService.loadModels(done);
},
// Clean out database
function (done) {
// Attempt to unlock jobs that were stuck due server restart
// See https://github.com/agenda/agenda/issues/410
worker.unlockAgendaJobs(done);
},
function () {
// Start the worker
worker.start({
maxAttempts: 10,
retryDelaySeconds: 10
});
}
], function (err) {
if (err) {
console.log('[Worker] error on initializing worker:');
console.error(err);
}
});