polly

Use a specific timeout connected to a retrypolicy

本秂侑毒 提交于 2019-11-30 23:45:31
I'm creating a retry policy the following way: var policy = Policy.Handle<Exception>().WaitAndRetryAsync... How to chail/build a timeout for the retrypolicy above? Policy.TimeoutAsync returns a TimeoutPolicy , hence I'm not able to do something like var policy = Policy.TimeoutAsync(30).Handle<Exception>().WaitAndRetryAsync... . Does the timeout become a common setting for all my retry policies? To combine policies, you build each policy separately, then combine them using PolicyWrap . To build an overall timeout which applies across all retries as a whole (ie across the entire operation): var

Set a default Polly policy with Flurl

元气小坏坏 提交于 2019-11-30 19:31:30
问题 I'm currently using Polly and Flurl together, but I have a common retry policy that I have to add to every request. I notice that Polly allows you to set a default using AddPolicyHandler(...) but this requires an IHttpClientBuilder and I can't see any way of getting hold of this from Flurl. I thought overloading DefaultHttpClientFactory might be the way to go, but that only gives me access to the HttpClient, not the IHttpClientBuilder. I know I could make my own HttpClients and pass them into

Use a specific timeout connected to a retrypolicy

我与影子孤独终老i 提交于 2019-11-30 18:01:06
问题 I'm creating a retry policy the following way: var policy = Policy.Handle<Exception>().WaitAndRetryAsync... How to chail/build a timeout for the retrypolicy above? Policy.TimeoutAsync returns a TimeoutPolicy , hence I'm not able to do something like var policy = Policy.TimeoutAsync(30).Handle<Exception>().WaitAndRetryAsync... . Does the timeout become a common setting for all my retry policies? 回答1: To combine policies, you build each policy separately, then combine them using PolicyWrap. To

Check string content of response before retrying with Polly

纵然是瞬间 提交于 2019-11-30 16:02:07
I'm working with a very flaky API. Sometimes I get 500 Server Error with Timeout , some other time I also get 500 Server Error because I gave it input that it can't handle SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. . Both of these cases give me HttpRequestException but I can look into the reply message from the server and determine the cause of the exception. If it is a timeout error, I should try again. If it is a bad input I should re-throw the exception, because no amount of retries will fix the problem of bad data. What I'd like to do with Polly

Polly Circuit breaker pattern - For testing connection strings

孤人 提交于 2019-11-29 17:02:58
I'm trying to test whether the connection string is null using Polly. If it is null, I want to try three times using the CircuitBreaker and the message should be outputted in the Console window. Policy policy = null; // Break the circuit after the specified number of exceptions // and keep circuit broken for the specified duration. policy = Policy .Handle<NullReferenceException>() .CircuitBreaker(3, TimeSpan.FromSeconds(30)); try { string connected = policy.Execute(() => repository.GetConnectionString()); } catch (Exception ex) { Console.WriteLine("{0}",ex.Message); } and the

Polly Circuit breaker pattern - For testing connection strings

梦想与她 提交于 2019-11-28 11:23:45
问题 I'm trying to test whether the connection string is null using Polly. If it is null, I want to try three times using the CircuitBreaker and the message should be outputted in the Console window. Policy policy = null; // Break the circuit after the specified number of exceptions // and keep circuit broken for the specified duration. policy = Policy .Handle<NullReferenceException>() .CircuitBreaker(3, TimeSpan.FromSeconds(30)); try { string connected = policy.Execute(() => repository