I setup a kue job as I usually do :
var job = jobs.create('phase2', s);
job.on('complete', function (){
console.log('Job'+job.id+' is done');
}).on('failed', function (){
console.log('Job'+job.id+'has failed');
});
job.save();
On certain conditions, I want the job to fail and restart automatically. For that, I have in my processor the following lines :
if(t==1){
//Keep going
}else{
console.log('PROBLEM');
job.failed();
}
I have tried changing the failed event to :
.on('failed', function (){
console.log('Job'+job.id+'has failed');
job.state('inactive').save();
});
as suggested here : Node.js Kue how to restart failed jobs
I have also tried adding attempts() as in the Readme, like so :
var job = jobs.create('phase2', s).attempts(5);
None of these things have worked. The job is marked as 'failed' and my console shows 'PROBLEM', but I do not see the message defined in the 'failed' listener.
EDIT
After more reading, i've tried listening to the 'job failed' event at queue level, using :
jobs.on('job failed', function(id,result){
console.log('fail queue');
kue.Job.get(id, function(err, job){
job.state('inactive').save();
});
});
Same result, and no console log... It seem to be something else than Kue, any idea what could make the events not fire?