Created
September 3, 2015 14:36
-
-
Save kulbirsaini/4d4728f30282702b7105 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
'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