Skip to content

Instantly share code, notes, and snippets.

@kulbirsaini
Created September 3, 2015 14:36
Show Gist options
  • Save kulbirsaini/4d4728f30282702b7105 to your computer and use it in GitHub Desktop.
Save kulbirsaini/4d4728f30282702b7105 to your computer and use it in GitHub Desktop.
'use strict';
var kue = require('kue');
var queue = kue.createQueue({ initialJobId: 10000 });
function createJobs() {
for (var i = 0; i < 101; i++) {
(function() {
var job = queue.create('test', { id: i }).save(function(error) {
console.log('Created job', job.id);
});
})();
}
}
function consumeJobs() {
queue.process('test', 1, function(job, ctx, done) {
console.log('Processing job', job.id);
done();
});
}
function getCompleteJobs() {
kue.Job.rangeByType('test', 'complete', 0, 100, 'asc', function(error, jobs) {
jobs.forEach(function(job) {
console.log('Received completed job', job.id);
});
});
}
createJobs();
setTimeout(function() { consumeJobs(); }, 2000);
setTimeout(function() { getCompleteJobs(); }, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment