Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set retry count to 0 by default for all Hangfire jobs?

Tags:

hangfire

I am using C# ASP.NET Core 3.1 with Hangfire to schedule background jobs. By default if an exception occurs during the execution of the background job, there are 10 retry attempts. I am aware it is possible to use the AutomaticRetry attribute to set that to 0, but I don't want to do that on every single background job. Instead I want the default to be 0 and to only specify it manually with the attribute in the very very rare case that I want it to be non-0. Thanks.

like image 715
Tri-Edge AI Avatar asked Oct 24 '25 01:10

Tri-Edge AI


1 Answers

I used to do it like this in .Net Classic, I guess it should not be so different in .Net Core

// disable automatic retry if a job fails
Hangfire.GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute() { Attempts = 0 }); 
like image 103
jbl Avatar answered Oct 27 '25 03:10

jbl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!