forked from forwardemail/forwardemail.net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bull.js
55 lines (45 loc) · 1.37 KB
/
bull.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
const Bull = require('@ladjs/bull');
const Graceful = require('@ladjs/graceful');
const pSeries = require('p-series');
const config = require('./config');
const queues = require('./queues');
const logger = require('./helpers/logger');
const bull = new Bull({
logger,
queues,
queue: {
prefix: `bull_${config.env}`
}
});
if (!module.parent) {
const graceful = new Graceful({
bulls: [bull],
logger
});
(async () => {
try {
const migration = bull.queues.get('migration');
await pSeries([() => migration.empty(), () => migration.add()]);
const vanityDomains = bull.queues.get('vanity-domains');
await pSeries([() => vanityDomains.empty(), () => vanityDomains.add()]);
const translateMarkdown = bull.queues.get('translate-markdown');
await pSeries([
() => translateMarkdown.empty(),
() => translateMarkdown.add()
]);
const translatePhrases = bull.queues.get('translate-phrases');
await pSeries([
() => translatePhrases.empty(),
() => translatePhrases.add()
]);
await Promise.all([bull.start(), graceful.listen()]);
if (process.send) process.send('ready');
logger.info('Lad job scheduler started');
} catch (err) {
logger.error(err);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
})();
}
module.exports = bull;