質問

I have seen questions like this but they do not answer my question.

I have a function

var kue = require('kue');
var jobs = kue.createQueue();

var create_job = function(data, callback){
    jobs.create('job', {
        stuff: data   
    }).save();
}

How can I make it so that callback is called when jobs.process('job', function(job, done){ ... is finished?

役に立ちましたか?

解決

I've not used kue before, so this is going off their documentation:

var kue = require('kue');
var jobs = kue.createQueue();

var create_job = function(data, callback){
    var job = jobs.create('job', {
        stuff: data   
    }).save();
    job.on('complete', function(){
        callback();
    }).on('failed', function(){
      callback({error: true});
    });    
};

I've created/used a JavaScript closure to capture the value of the callback argument (by attaching the events within the scope of the create_job function, and it's later called when the function completes (or fails).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top