I'm using kue in one web crawler application. I want to set attempts
for certain failed jobs if the errors match specific conditions. For instance if the error is caused by socket hang up, the job will retry for 3 times with 1 min interval.
My code is something like below but does not work
var kue = require('kue');
var queue = kue.createQueue();
queue.process('grab', function (job, done){
//doCrawlingJob is async call and returns promise
doCrawlingJob(job).then(function(result){
done();
}.catch(function(err){
if (err.message.indexOf("socket hang up") >= 0) {
job.attempts(3).backoff({delay:60*1000});
job.save(function(){
done(err);
});
} else {
done(err);
}
);
});
//...
var job = queue.create('grab', data).removeOnComplete(true).save();
This may not answer your question but I noticed that you have some formatting errors in the code snippet. Try adding some brackets like so: