-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.js
53 lines (49 loc) · 1.25 KB
/
queue.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
const kue = require("kue");
const {
host,
port,
auth,
shutdownTimeout,
watchdogInterval
} = require("./config");
const queue = kue.createQueue({
redis: {
host,
port,
auth
}
});
// ========================================
// queue events
// ========================================
queue
.on("error", function(err) {
console.log("Error occured in the queue.", err);
})
.on("job enqueue", function(id, type) {
console.log("job %s got queued of type %s", id, type);
})
.on("job complete", function(id, result) {
kue.Job.get(id, function(err, job) {
if (err) return;
job.remove(function(err) {
if (err) throw err;
console.log("removed completed job #%d", job.id);
});
});
});
// ========================================
// watch stuck jobs
// ========================================
queue.watchStuckJobs(watchdogInterval);
// ========================================
// queue shutdown
// ========================================
process.once("SIGTERM", function(sig) {
console.log("[ Shutting down when all jobs finish... ]");
queue.shutdown(shutdownTimeout, function(err) {
console.log("[ All jobs finished. Kue is shut down. ]");
process.exit(0);
});
});
module.exports = queue;