如何在Redis Bull队列中传递完整请求或响应

时间:2018-03-15 13:51:37

标签: node.js redis promise queue response

使用公牛队列可能是一种错误的方法,但这就是我想要做的事情:

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)
});

在我的真实项目中,我想实现队列,我将向用户发送pdf。与res.download(pdf path);类似,但此功能应该在pdf.on('completed',()=>{ res.download(pdf path); });resolve(pdfPath)中,但我无法找到使用队列向用户发送pdf,因为我不知道如何使用队列作业调用响应或解析其他功能。

请帮帮我。谢谢你

0 个答案:

没有答案