Set a default Polly policy with Flurl

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 Flurl, but I'd rather avoid that if I can as I'd like ...Read more

Polly timeout before execute is called

I have a policy which I execute like this:_logger.LogDebug($"Got the policy for {tenant.TenantCode}");policy.Execute( () => { _logger.LogDebug($"Calling _domainEventDLA.GetOldestEvent {tenant.TenantCode}"); domainEvent = _domainEventDLA.GetOldestEvent(tenant); _logger.LogDebug($"Calling _domainEventDLA.GetOldestEvent {tenant.TenantCode}"); } );I have a timeout set to 3 seconds and I get the polly timeout exception. The method in the execute takes less than 100 milliseconds. In the log ...Read more

Which wait mechanism is Polly using

Polly has several retry functionalities like for example WaitAndRetryForever. I looked in the documentation but couldn't find what is used exactly for making the thread wait until the next retry. I guess Polly uses System.Timers for this or is it something completely different? Thanks for any collaboration....Read more

polly - Can I modify a Policy after it is built?

I'm creating an API method call which takes a Policy as an argument.However, in my method I'd like to 'add onto' this policy by including my own retry Action(s) so that I can perform intermediate logging and telemetry of my own. Similar in concept to adding Click events to a Windows UI control.Is there a way to modify a Policy after it's created?Or, is there a hook mechanism where I can define my own callbacks in the Execute method perhaps?Thanks-John...Read more

Polly does not do the retry action

I have created a simple scenario to test the Polly I might be totally wrong. If it does the retry, the retries variable should be 3.Please take a look at what I have done.Thanks.void Something(int Try) { try { if (Try <= 3) throw new InvalidStudentNameException(); } catch { } } protected void Button1_Click(object sender, EventArgs e) { int retries = 0; try { Something(...Read more

Composing a Polly Policy with user feedback

There are several policy's that need to be the same throughout my code. For example:var myIOProblems = Policy .Handle<IOException>() .WaitAndRetryForever(i => TimeSpan.FromSeconds(2));Then I'll have some code that will do the work:myIOProblems .Execute(() => otherPath.CopyTo(otherPathPart.FullName));This works great, and I can litter the latter statements all over my code, change the behavior in one central place, and it all seems to work.But in some places I need to provide the user/framework some feedback that problems are oc...Read more

How to cancel pending retries on Polly's async WaitAndRetryPolicy

I‘m using polly for a simple retry n-times szenario on a HTTP POST-request. It should handle any exception and retry to post my payload to the api-endpoint for n-times. Therefore I used a WaitAndRetryPolicy wraping a TimoutPolicy with a pessimistic strategy for a timeout per try. Both as async policies.When the retry-case is taking place every retry-attempt, which was made, is posted to the endpoint after connection is re-esteblished.The method which wraps the two policies up: public static PolicyWrap WaitAndRetryNTimesWithTimeoutPerTry(int ...Read more

What am I missing in this that Polly is not retrying my action?

public class PollyTest{ public void RunWithPolly() { Console.WriteLine("RunWithPolly invoked..."); int zero = 0; int result= 10 / zero; }}And in my Main function I create a Policy as below:var retryPolicy = Policy.Handle<DivideByZeroException>().Retry(3);PollyTest pollyTest = new PollyTest();retryPolicy.Execute(() => pollyTest.RunWithPolly());When I execute this, it always fails with unhandled exception error inside function "RunWithPolly" on the very first run itself....Read more

polly - Action before retry

I have this use case where, for some errors, I need to perform an action before the retry; otherwise, just retry.Something like this:try{action: <action>}catch (SpecialException){ <cleanup> goto action:}catch (Exception){ goto action:}Is this possible with Polly?...Read more