Skip to content

Instantly share code, notes, and snippets.

@bradvogel
Created December 13, 2016 18:12
Show Gist options
  • Save bradvogel/872ea1e3ed39dd5351cbb5d43db326fa to your computer and use it in GitHub Desktop.
Save bradvogel/872ea1e3ed39dd5351cbb5d43db326fa to your computer and use it in GitHub Desktop.
bull
var Bull = require('bull');
var queue = new Bull('contacts', 6383, 'localhost');
var concurrency = process.argv[2] ? parseInt(process.argv[2]) : 1;
function handler(job, done) {
console.log('processing job', job.jobId);
setTimeout(() => {
done();
}, 5 * 1000);
}
queue.on('stalled', job => console.log('stalled: ', job));
queue.process(handler, {
concurrency: concurrency
});
var Bull = require('bull');
var queue = new Bull('contacts', 6383, 'localhost');
var numEvents = process.argv[2] ? parseInt(process.argv[2]) : 1;
queue.on('ready', () => {
for (var i = 0; i < numEvents; i++) {
setTimeout(() => {
queue.add({}, {
removeOnComplete: true
}).then(() => {
console.log('published job');
});
}, i * 500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment