method to permanently fail a job
Created by: bradvogel
Feature request: a method on the job, such as job.fail()
that can be called inside the job handler to move a job to failed (bypassing any more job attempts).
Use case:
We're creating jobs using the attempts
property, like this:
queue.add({}, {
attempts: 10
});
So jobs are automatically retried if an error is returned from the handler. However, there are circumstances in which the job handler might encounter a permanent error (such as something being removed the database that's needed by the handler), and it would be nice if it had the ability to stop the job from being retried.
So ideally it could call something like job.fail()
that would just fail the job:
queue.process(function (job, jobDone) {
if (permanentError){
job.fail(); // Will move the job to 'failed' after it's finished
}
jobDone();
});
How does this sound? I can file a PR.