-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestQueueOfKue.js
58 lines (43 loc) · 1.22 KB
/
testQueueOfKue.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
56
57
58
/**
* 测试 任务队列框架 kue
* Created by chaclus on 2017/2/15.
*/
var kue = require('kue');
var queue = kue.createQueue({
prefix: 'kue_q',
redis: {
port: 6379,
host: '192.168.3.30',
auth: 'TUTU@live2016',
db: 0,
}
});
queue.on( 'error', function( err ) {
console.log( 'Oops... ', err );
});
var addJob = function () {
var job = queue.create('email', {
title: 'welcome email for tj'
, to: '[email protected]'
, template: 'welcome-email'
}).save(function (err) {
if (!err) console.log("add and get the job id: ",job.id);
});
job.on('complete', function (result) {
console.log('Job completed with data ', result);
}).on('failed attempt', function (errorMessage, doneAttempts) {
console.log('Job failed');
}).on('failed', function (errorMessage) {
console.log('Job failed');
}).on('progress', function (progress, data) {
console.log('progress #### ' + job.id + ' ' + progress + '% complete with data ', data);
});
};
var processJob = function () {
queue.process('email', function(job, done){
console.log("job: ", job.data);
done();
});
};
addJob();
processJob();