Reputation: 5125
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?
Upvotes: 1
Views: 1462
Reputation: 59763
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).
Upvotes: 3