You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privateIAsyncPolicy<HttpResponseMessage>GetRetryPolicy(intnumRetries=10,intdelayInMilliseconds=10000){varretryPolicy= Policy
.Handle<HttpRequestException>().OrResult<HttpResponseMessage>(r => r.StatusCode == HttpStatusCode.TooManyRequests || r.StatusCode == HttpStatusCode.ServiceUnavailable).WaitAndRetryAsync(numRetries,
sleepDurationProvider:(retryCount,response,context)=>{vardelay= TimeSpan.FromSeconds(0);// if an exception was thrown, this will be nullif(response.Result !=null){if(!response.Result.Headers.TryGetValues("Retry-After",outIEnumerable<string> values))returndelay;if(int.TryParse(values.First(),outint delayInSeconds))delay= TimeSpan.FromSeconds(delayInSeconds);}else{varexponentialBackoff= Math.Pow(2, retryCount);vardelayInSeconds=exponentialBackoff*delayInMilliseconds;delay= TimeSpan.FromMilliseconds(delayInSeconds);}returndelay;},
onRetryAsync:async(response,timespan,retryCount,context)=>{// add your logging and what you want to do});returnretryPolicy;}
App-vNext/Polly.Extensions.Http#26
The text was updated successfully, but these errors were encountered: