Skip to content

Instantly share code, notes, and snippets.

@sz332
Last active August 29, 2019 07:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sz332/4412f130214ec2bb02078e88c2ee1462 to your computer and use it in GitHub Desktop.
Save sz332/4412f130214ec2bb02078e88c2ee1462 to your computer and use it in GitHub Desktop.
Working example of bull and external processor
// index.js
const path = require('path');
const Queue = require('bull');
let queue = new Queue('test queue', 'redis://192.168.99.100:6379');
queue.process(1, path.join(__dirname, './processor.js'))
queue.on('completed', function(job, result) {
console.log("Completed: " + job.id + ", result = " + JSON.stringify(result));
job.remove();
});
queue.add({ text: 'Hello world...' }).then(job => {
console.log("Job started with id = " + job.id);
});
// processor.js
module.exports = function(job) {
console.log("data = " + JSON.stringify(job.data));
console.log("Started working on job: " + job.id);
return Promise.resolve({ 'data': 123 });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment