Last active
September 13, 2016 08:18
-
-
Save Bersam/0a6138959ded1be332b1b12d857eefcd to your computer and use it in GitHub Desktop.
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
var PQ = require("bull/lib/priority-queue"); | |
var testQ = PQ("test:seek", 7777, '127.0.0.1'); | |
var priorities = [ | |
"low", | |
"normal", | |
"medium", | |
"high", | |
"critical" | |
]; | |
var delay = 1000; | |
var activeJob = 0; | |
testQ.process(function(job, jobDone) { | |
activeJob++; | |
// console.log("job", job.jobId, "started"); | |
// console.log("job priority", job.data.rand); | |
console.log("active jobs in progress", activeJob); | |
setTimeout(function(){ | |
activeJob--; | |
// console.log("job", job.jobId, "done"); | |
jobDone(); | |
},delay * 3); | |
}); | |
testQ.resume(); | |
testQ.resume(); | |
testQ.resume(); | |
testQ.resume(); | |
testQ.resume(); | |
// generator | |
setInterval(function() { | |
var rand = priorities[Math.floor(Math.random() * priorities.length)]; | |
testQ.add({rand: rand}, { | |
priority: rand | |
}); | |
}, delay); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment