Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass arbitrary data to Policy execution #1

Closed
waynebrantley opened this issue May 25, 2013 · 2 comments
Closed

Pass arbitrary data to Policy execution #1

waynebrantley opened this issue May 25, 2013 · 2 comments

Comments

@waynebrantley
Copy link

I have a generic policy, like this:

        private static readonly Policy _basicRetryPolicy = Policy
                                        .Handle<Exception>()
                                        .WaitAndRetry(3,
                                        retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt + 3)),  //exponetial backoff, 2^4, 2^5 and 2^6 seconds between retry (16sec, 32sec and 64sec)
                                        (exception, timespan) =>
                                        {
                                            Logger.Info("Retry operation - wait :" + timespan.TotalSeconds.ToString());
                                        });

Now you can see I am writing to a log when the retry operation happens. However, I am using this same policy for many different Execute() functions. I would like to perhaps be able to pass some data, maybe just a string that says what call this is - so when the log is written it can accurately record which operation is retrying.

Is there a way to do this - if not, do you think it is a valuable addition to your library (perhaps as an optional parameter to the Execute() call - and then that parameter passed into the lambdas like timespan/retryattempt/exception is?

@michael-wolfenden
Copy link
Contributor

I think this is a really good idea and I will look into implementing it.

In the meantime, you can probably get information about the call that raised the exception from either the exception itself or the call stack. See How to get the name of the method that caused the exception for more information.

@waynebrantley
Copy link
Author

Great, thanks...

asherw pushed a commit to asherw/Polly that referenced this issue May 4, 2015
…evel

Add service level circuit breaker state
joelhulen pushed a commit that referenced this issue Apr 14, 2016
…dedWindows

Merge code which divides the timeslice of the TimesliceCircuitBreaker into internal windows, for smoothing of statistics at timeslice rollver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants