2

It may be a wrong way to use bull queue but here is what I want to do:

var Promise = require('bluebird');
var redis = require('redis');
var Queue = require('bull');

var redisClient = redis.createClient(6379);

var pdfQueue = new Queue('msg');

function check(resolve, reject,i) {
    console.log('check called');

    //Or if it is in Router then I want to send request, response in queue so that I can call them in on complete function
   pdfQueue.add('msg',{'msg':'Hello', 'resolve':resolve,'reject':reject}).then(job=>{
       console.log('added to the pdf')
   });

}

pdfQueue.on('completed', function (job, result) {
    //Here I want to call request.send('some msg');
    //and resolve('complete');
    resolve('final callback');
})

pdfQueue.process('msg',100,function (job,done) {
    console.log('process');
    done(null,'job done ')
})


function check2 () {
    return new Promise(function(resolve, reject){
        check(resolve,reject);
    })
}

check2().then(data => {
    console.log('got the value ', data)
});

In my real project I want to implement queue where I will be sending pdf to the user. Like res.download(pdf path); but this function should be in pdf.on('completed',()=>{ res.download(pdf path); }); or in resolve(pdfPath) but I am not able to find anyway to send pdf to the user using queue because I don't know how to call response or resolve in other functions by using queue jobs.

Please help me. Thanks you

  • The documentation is pretty poor but I would guess that `Queue.on('completed' (job, result) => {...})` fires once per job, not once for the whole queue, as you appear to expect. – Roamer-1888 Mar 16 '18 at 19:38
  • yes I know but how would I be able to access response variable in that function? If I put `Queue.on('completed',())` in calling function then it calls Queue.on several times. – Deepak Kumar Mar 18 '18 at 18:10
  • 1
    Are you sure to need `queue.on("completed", ...` here? I don't see any Express code, but [How to listen to the completed event in bull queue - just for the current job](https://stackoverflow.com/questions/55454493/how-to-listen-to-the-completed-event-in-bull-queue-just-for-the-current-job/67609723#67609723) shows how to get a repsonse back to the client after processing finishes using `job.finished()`. – ggorlen May 19 '21 at 19:56

0 Answers0