I would like to try an action three times and if it fails then call fallback... For example something like this:
Policy.Handle
.WaitAndRetry(retryCount: 7, sleepDurationProvider: (attempt) => { return TimeSpan.FromSeconds(value: Math.Pow(attempt, 2)); })
.Execute(action: () => {
this.DoTheMagic();
}).
Fallback(()=>{ this.LogThatMagicWasNotDone();}
;
but it does not work. How to achieve such behavior? Or do I have to insert whole Polly call into my own try-catch statement?
Additionaly, am I able to somehow inject code after every failed attempt? So that I can log for example "Attempt number X: failed"?
Thanks!
@romanb52
To combine policies, see PolicyWrap.
To run code after each failure, use the overloads of WaitAndRetry(...) where you can configure an onRetry: delegate - see readme
Here's an example I wrote a while back in dotnetfiddle.
Closing. If you need further assistance, though, do open another issue - or post a query on our slack channel
Most helpful comment
@romanb52
To combine policies, see PolicyWrap.
To run code after each failure, use the overloads of
WaitAndRetry(...)where you can configure anonRetry:delegate - see readmeHere's an example I wrote a while back in dotnetfiddle.