forked from Trustroots/trustroots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
55 lines (50 loc) · 1.13 KB
/
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
47
48
49
50
51
52
53
54
55
/**
* Trustroots
*
* Worker main entry file
*/
const config = require('./config/config');
const async = require('async');
const mongooseService = require('./config/lib/mongoose');
const worker = require('./config/lib/worker');
const log = require('./config/lib/logger');
const Sentry = require('@sentry/node');
if (config.sentry.enabled) {
Sentry.init(config.sentry.options);
}
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) {
log(
'error',
'[Worker] Error while initializing the background job worker.',
err,
);
}
},
);