-
Notifications
You must be signed in to change notification settings - Fork 5
/
server.js
61 lines (48 loc) · 1.32 KB
/
server.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
59
60
61
var kue = require( 'kue' );
// create our job queue
var jobs = kue.createQueue();
// one minute
var minute = 60000;
var email = jobs.create( 'email', {
title: 'Account renewal required', to: '[email protected]', template: 'renewal-email', job_id: 1,
} ).delay( minute )
.priority( 'high' )
.save(function() {
console.log(email.id);
});
email.on( 'promotion', function () {
console.log( 'renewal job promoted' );
} );
email.on( 'complete', function () {
console.log( 'renewal job completed' );
} );
jobs.create( 'email', {
title: 'Account expired', to: '[email protected]', template: 'expired-email', job_id: 2,
} ).delay( minute * 10 )
.priority( 'high' )
.save();
jobs.promote();
jobs.process( 'email', 10, function ( job, done ) {
setTimeout( function () {
done();
}, Math.random() * 5000 );
} );
// you have the job_id
var job_id_to_update = 1;
// get delayed jobs
jobs.delayed( function( err, ids ) {
ids.forEach( function( id ) {
kue.Job.get( id, function( err, job ) {
// check if this is job we want
if (job.data.job_id === job_id_to_update) {
// change job properties
job.data.title = 'set another title';
// save changes
job.update();
}
});
});
});
// start the UI
kue.app.listen( 3000 );
console.log( 'UI started on port 3000' );