Last active
October 24, 2016 09:35
-
-
Save 1yx/3c5e0211da842755ebec6ddd225f1c65 to your computer and use it in GitHub Desktop.
kue demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const kue = require('kue'); | |
kue.createQueue({ | |
prefix: 's9', | |
redis: { | |
host: 'localhost', | |
db: 1 | |
} | |
}); | |
kue.app.listen(8000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const kue = require('kue'); | |
const queue = kue.createQueue({ | |
prefix: 's9', | |
redis: { | |
host: 'localhost', | |
db: 1 | |
} | |
}); | |
queue.process('push', (job, done) => { | |
setTimeout(() => { | |
console.log('push notification' + job.data.uid); | |
done(); | |
}, 2000); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "kue-demo", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "xo" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"kue": "^0.11.4" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const kue = require('kue'); | |
const queue = kue.createQueue({ | |
prefix: 's9', | |
redis: { | |
host: 'localhost', | |
db: 1 | |
} | |
}); | |
let sequence = 0; | |
setInterval(() => { | |
sequence += 1; | |
((sequence) => { | |
const job = queue.create('push', { | |
uid: sequence | |
}).removeOnComplete(true).delay(1000).priority('high').save(); | |
job.on('start', () => { | |
console.log('#' + sequence + ' start', new Date()); | |
}).on('complete', () => { | |
console.log('#' + sequence + ' complete', new Date()); | |
}).on('complete', () => { | |
console.log('#' + sequence + ' remove', new Date()); | |
}); | |
})(sequence); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment