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

Any reason OnHalfOpen doesn't take a context? #806

Closed
rmiller333 opened this issue Nov 4, 2020 · 2 comments
Closed

Any reason OnHalfOpen doesn't take a context? #806

rmiller333 opened this issue Nov 4, 2020 · 2 comments

Comments

@rmiller333
Copy link

rmiller333 commented Nov 4, 2020

Is your feature request related to a specific problem? Or an existing feature? Please describe.

I'm using a context to pass a logger. Since it's on an httpClient in my case, it's really just a static logger and I should be able to use one. However, I'd like to leverage the infrastructure to use the context to get the logger and reduce statics floating around.

This didn't work since I didn't see an overload that takes a context for onHalfOpen. Is there a reason it doesn't take a context?

return Policy<HttpResponseMessage>
                .HandleResult(r => !r.IsSuccessStatusCode)
                .CircuitBreakerAsync(
                    siftPollySettings.ConsecutiveExceptionsAllowedBeforeBreaking,
                    TimeSpan.FromSeconds(siftPollySettings.DurationOfBreakInSeconds),
                    onBreak: (ex, breakDelay, context) =>
                    {
                        var logger = context.GetLogger();
                        logger.LogMap(LogLevel.Error, "SiftExtensions.AddSift.ExcessiveErrors.PollyBreakingSiftCalls", new Dictionary<string, object>()
                        {
                            { "durationSeconds", siftPollySettings.DurationOfBreakInSeconds },
                            { "ex", ex },
                        });
                    },
                    onReset: (context) =>
                    {
                        var logger = context.GetLogger();
                        logger.LogWarning("SiftExtensions.AddSift.PollyResumingSiftCalls");
                    },
                    onHalfOpen: (context) =>
                    {
                        var logger = context.GetLogger();
                        logger.LogWarning("SiftExtensions.AddSift.PollyTestingResumingSiftCalls");
                    });

Any additional info?

@rmiller3
Copy link

rmiller3 commented Nov 5, 2020

I just found this, which describes why. #311 (Mar25-2019 response)

I just have to decide if a static logger is better or no log is better for onHalfOpen.

@SimonCropp
Copy link
Contributor

seems you have resolved this yourself. Will close for now

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

3 participants