-
Notifications
You must be signed in to change notification settings - Fork 1
/
queues.js
50 lines (41 loc) · 1.31 KB
/
queues.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
'use strict';
exports = module.exports = function(app) {
if(app.config.queue.enabled) {
var queue = require('bull');
var defaultQueue = queue('default', app.config.queue.redis.port,
app.config.queue.redis.host, {auth_pass: app.config.queue.redis.password});
defaultQueue.process(function(job, done){
// job.data contains the custom data passed when the job was created
// job.jobId contains id of this job.
// transcode video asynchronously and report progress
job.progress(42);
// call done when finished
done();
// or give a error if error
done(Error('error transcoding'));
// If the job throws an unhandled exception it is also handled correctly
throw (Error('some unexpected error'));
});
// add Things to the queue
// defaultQueue.add({ aKey: "aValue" });
defaultQueue.on('completed', function(job){
// Job completed!
})
.on('failed', function(job, err){
// Job failed with reason err!
})
.on('progress', function(job, progress){
// Job progress updated!
})
.on('paused', function(){
// The queue has been paused
})
.on('resumed', function(job){
// The queue has been resumed
});
//share the queues
app.queues = {
default: defaultQueue
};
}
};