-
Notifications
You must be signed in to change notification settings - Fork 0
/
processor.js
44 lines (37 loc) · 994 Bytes
/
processor.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
const kue = require("kue");
const { host, port, auth } = require("./config");
const queue = kue.createQueue({
redis: {
host,
port,
auth
}
});
const concurrency = 2; // default
queue.process("A-A", concurrency, function(job, done) {
setTimeout(function() {
const { data } = job;
data.extra = "A";
if (!((Math.random() * 3) | 0))
done(new Error("Oops! This doesn't look good."));
else done(null, data);
}, 2000);
});
queue.process("A-B", concurrency, function(job, done) {
setTimeout(function() {
const { data } = job;
data.extra = "B";
if (!((Math.random() * 3) | 0))
done(new Error("Oops! This doesn't look good."));
else done(null, data);
}, 2000);
});
queue.process("A-C", concurrency, function(job, done) {
setTimeout(function() {
const { data } = job;
data.extra = "C";
if (!((Math.random() * 3) | 0))
done(new Error("Oops! This doesn't look good."));
else done(null, data);
}, 2000);
});