Skip to content

Instantly share code, notes, and snippets.

@Bersam
Last active September 13, 2016 08:18
Show Gist options
  • Save Bersam/0a6138959ded1be332b1b12d857eefcd to your computer and use it in GitHub Desktop.
Save Bersam/0a6138959ded1be332b1b12d857eefcd to your computer and use it in GitHub Desktop.
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