HOWTO: Retry a job n times and run code on failure of all n times


We’re impressed with Hangfire and are cleaning up the final bits on our internal application. We have a question, however.

Given a Job handled by BackgroundJob.Enqueue (or similar), is it possible to have the job retry and if it should fail all those retries, for my code to pick up that failure and process it accordingly? We’d like to put the underlying task into a “Failed” state if the job permanently failed.



This could work? Enqueue a new job if last retry fail