Last active
August 29, 2019 07:53
-
-
Save sz332/4412f130214ec2bb02078e88c2ee1462 to your computer and use it in GitHub Desktop.
Working example of bull and external processor
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
// 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); | |
}); |
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
// 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