Nimish David Mathew
Nimish David Mathew

Reputation: 3168

Identify completion of final retry by Polly retry policy

How do I identify the completion (not onRetry event, but the actual execution and completion) of the final retry in Polly?

I could compare the retry count with max retry count inside the onRetry event, but the event is just the initiation of a retry which is yet to happen within the wait duration. What I want to do is identify the end of the final retry be it a success or fail.

Upvotes: 3

Views: 2197

Answers (1)

mountain traveller
mountain traveller

Reputation: 8156

What I want to do is identify the end of the final retry be it a success or fail.

You can use Polly's ExecuteAndCaptureAsync() in place of .ExecuteAsync().

ExecuteAndCaptureAsync() returns a PolicyResult object with PolicyResult.Outcome == OutcomeType.Successful or OutcomeType.Failure (among other properties covered in the documentation).


If sticking with .ExecuteAsync() rather than ExecuteAndCaptureAsync(), the end of the final try is identified (on success) by execution continuing to the next statement; or (on failure) by the policy rethrowing the final exception. ExecuteAndCaptureAsync() is only a wrapper for those behaviours.

Upvotes: 5

Related Questions