-
Notifications
You must be signed in to change notification settings - Fork 3
/
worker.js
46 lines (40 loc) · 1.15 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
const Queue = require('bee-queue');
const { compress, download, deleteFile } = require('./utilities');
const options = {
removeOnSuccess: true,
removeOnFailure: true,
redis: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
password: process.env.DB_PASS,
}
}
const downloadQueue = new Queue('kti_dwl', options);
const compressQueue = new Queue('kti_cmp', options);
const stagingQueue = new Queue('kti_stg', {
...options,
storeJobs: false,
activateDelayedJobs: true
});
downloadQueue.process(5, (job) => {
return download(job);
})
compressQueue.process(3, (job) => {
return compress(job);
})
stagingQueue.process((job) => {
return new Promise((resolve, reject) => {
deleteFile(`./public/${job.id}.pdf`)
.then(() => deleteFile(`./public/${job.data}`))
.then(() => { resolve() })
.catch((err) => console.log("Error deleting files", err))
})
})
const shutdown = () => {
console.log("Worker shutting down");
downloadQueue.close(5);
compressQueue.close(5);
stagingQueue.close(5);
}
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);