A process after reaching max retry

Hi, is there a way to process a job/methods when max automatic retry?
Let’s say, I have a job to send email to customer after a customer orders, and I would like to cancel the order if the sending a notification email job reaches the max retry and fails.

You could create your own retry handler with a IElectStateFilter and do your logic in the OnStateElection method when context.CandidateState is in FailedState.
If you want to keep track on how many tries has been made you can set/get it with context.SetJobParameter("RetryCount", retryAttempts) and retryAttempts = context.GetJobParameter<int?>("RetryCount") ?? 0.

You can get the idea on how it is implemented in the framework here:

1 Like