I set up a bull/redis queue in my express project:
count_to_ten.js:
module.exports = function(queue) {
console.log('Preparing Job: count to ten');
queue.process(function(job, done) {
console.log('Starting job: ' + job.data.name)
for (var i = 0; i <= 10; i++) {
console.log('Index: ' + i);
}
done()
})
}
And I set up the queue like this:
const defaultQueue = new Queue('default', 'redis://127.0.0.1:6379');
const worker = require('../jobs/count_to_ten')
worker(defaultQueue)
Then I finally try to trigger the background processing from my router/controller:
queue.add( { name: 'JohnDoe' } )
Which seems to work fine, I see the logs counting to ten, and I assume it is running on the background as it is not hanging my request (I am using nodemon)
However, I never get to see a completed callback (I added this to my routes file, after I call add):
queue.on('completed', function(job, result) {
console.log(`Job ${job.id} completed`);
});
Am I doing something wrong here?
EDIT: I am not really sure anymore if the processing is happening in the background by now. Should I have a separate daemon for the background process?