question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WaitAndRetryForever variants: add overloads where onRetry takes retry number

See original GitHub issue

Method WaitAndRetryAsync do have an override: public static RetryPolicy WaitAndRetryAsync(this PolicyBuilder policyBuilder, int retryCount, Func<int, Context, TimeSpan> sleepDurationProvider, Action<Exception, TimeSpan, int, Context> onRetry) allowing to log exception together with number of attempt during which it ocurred:

Policy
    .Handle<ArgumentException>()
    .WaitAndRetryAsync(10, (rn, ctx) => TimeSpan.FromSeconds(1),
        (ex, ts, rc, ctx) => { Console.WriteLine($"Exception logged: {ex.GetType().Name}. Attempt: {rc}"); })

But method WaitAndRetryForeverAsync does not have similar override. As a workaround I could use WaitAndRetryAsync with int.MaxValue as first argument, but that is not the best look and feel especially when we have Forever counterpart method.

As a solution I can propose either add the missing override, or add retryAttemptNumber to Context class. Latter option would also help when retry attempt is needed during main action execution (mainly for logging purposes).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
reisenbergercommented, Jun 23, 2018

Hi @NRKirby Thank you for your interest in this! @Freakazoid182 has made a PR ( #471 ) on this just hours earlier, so it may no longer be ‘up-for-grabs’. @Freakazoid182 / both: I haven’t had the chance to read #471 today, but will do shortly. @NRKirby Do feel free to read #471; comments welcome!

0reactions
Freakazoid182commented, Jul 14, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

July 2017 - Dave's Tech Blog
I chose to use one of the WaitAndRetryAsync overloads, for which three arguments must be specified: The maximum number of retries to make....
Read more >
How can I get the retry count within a delegate executed ...
Retry policy already passes the retry count to the onRetry delegate, so the policy can capture this into the execution-scoped Context : var ......
Read more >
Working with Polly – Using the Context to Obtain the Retry ...
The WaitAndRetryAsync method, as one of its overloads, accepts an Action delegate, which as one of its arguments includes the Context object.
Read more >
Cancelling a Polly Retry policy - Chris Roberts
To pass our CancellationToken to the Policy, we create a Polly Context and add the token as a named dictionary item. We can...
Read more >
Implement HTTP call retries with exponential backoff ...
With Polly, you can define a Retry policy with the number of retries, the exponential backoff configuration, and the actions to take when ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found