Is there a way to disable re-queueing of a failed Hangfire BackgroundJob?
We do not want the failed jobs to be executed again as this might cause issues.
In the simplest case, such as using ThreadPool.QueueUserWorkItem or Task.Factory.StartNew methods, only thread is changed. But in Hangfire, you can use different process, or different server to process background jobs.
Hangfire can process multiple queues. If you want to prioritize your jobs, or split the processing across your servers (some processes for the archive queue, others for the images queue, etc), you can tell Hangfire about your decisions. To place a job into a different queue, use the QueueAttribute class on your method:
When Hangfire encounters external exception that occurred during the job performance, it will automatically try to change its state to the Failed one, and you always can find this job in the Monitor UI (it will not be expired unless you delete it explicitly).
If you want to prioritize your jobs, or split the processing across your servers (some processes for the archive queue, others for the images queue, etc), you can tell Hangfire about your decisions. To place a job into a different queue, use the QueueAttribute class on your method:
Solved, using [AutomaticRetry(Attempts = 0)]
You can either annotate the method to run in the background with the following attribute:
[AutomaticRetry(Attempts = 0)]
Or set it globally:
GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With