Quantcast
Channel: Active questions tagged retry-logic - Stack Overflow
Viewing all articles
Browse latest Browse all 950

Retry strategy with exponential timeout

$
0
0

I use Polly to retry HTTP Requests. The following code works fine:

IAsyncPolicy<HttpResponseMessage> waitTimeout = Policy.TimeoutAsync<HttpResponseMessage>(TimeSpan.FromSeconds(5));// Retry policy for transient errorsIAsyncPolicy<HttpResponseMessage> retry = HttpPolicyExtensions.HandleTransientHttpError()    .Or<TaskCanceledException>()    .Or<TimeoutRejectedException>()    .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable)    .OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.InternalServerError)    .WaitAndRetryAsync(12, _ => TimeSpan.FromSeconds(10));// Register the HTTP client with the Polly policiesbuilder.Services.AddHttpClient("ApiClient",        client => {client.Timeout = TimeSpan.FromSeconds(230); })    .AddHeaderPropagation()    .AddPolicyHandler(Policy.WrapAsync(retry, waitTimeout));

The time before the next retry is 10 seconds and the timeout for each request within the retry is 5 seconds.The problem is that the API service can respond slowly. I would like to have the exponential timeout for each request within retry (not delay time)


Viewing all articles
Browse latest Browse all 950

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>