Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable re-queueing of failed Hangfire BackgroundJob

Tags:

c#

hangfire

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.

like image 613
user2992766 Avatar asked Mar 04 '15 08:03

user2992766


People also ask

How to run a background job in Hangfire?

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.

How do I process multiple queues in Hangfire?

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:

What happens when a job fails in Hangfire?

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).

How do I prioritize my jobs in Hangfire?

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:


2 Answers

Solved, using [AutomaticRetry(Attempts = 0)]

like image 159
user2992766 Avatar answered Sep 22 '22 16:09

user2992766


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 }); 
like image 42
Owen Pauling Avatar answered Sep 19 '22 16:09

Owen Pauling