Here is my try:
private Policy retryPolicy { get; } = Policy
.Handle<IOException>()
.WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
private Policy bigFilePolicy { get; } = Policy
.Handle<UnauthorizedAccessException>()
.WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
retryPolicy.ExecuteAsync(() => bigFilePolicy.ExecuteAsync(command));
I am trying to make a retry policy for an automatic file upload system. When the file is too big, it takes some time to be dropped in the folder and while it loads, my program gives an unauthorized access exception, in such cases I am thinking of allowing WaitAndRetryForever for the big files. Otherwise, if it gets other exceptions it should not retry forever.
To mix policies together you need to call Policy.Wrap/Policy.WrapAsync. For example, you could do:
var exponentialBackoffPolicy = Policy.WrapAsync(retryPolicy, bigFilePolicy);
Or even:
var exponentialBackoffPolicy = retryPolicy.WrapAsync(bigFilePolicy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With