In my ASP.NET Core application, some long-running background tasks fail due to transient network errors, while others fail due to unrecoverable business validation issues. By default, Hangfire retries failed jobs up to 10 times.
Applying Retry Attributes
I know I can use the AutomaticRetry attribute at the method level:
// Customize retry attempts and strategy for a specific method
[AutomaticRetry(Attempts = 3, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
public void ProcessPayment(int orderId)
{
// Payment processing logic
PaymentGateway.Charge(orderId);
}Global Configuration Questions
I want to apply a default retry policy globally across all jobs while overriding it for specific background operations. How can I set a global retry attempt limit during registration in Program.cs? Also, how can I capture exceptions from a failed background job and send alert notifications to developers before the job is placed in the Deleted state?
Can you answer this question?
Write Answer0 Answers