BambooSoftwareLLC / HallPass.NET

Apache License 2.0
8 stars 0 forks source link

Use with Polly #2

Open hughesjs opened 2 years ago

hughesjs commented 2 years ago

A lot of us use Polly for retries to help add some resilience against transient errors.

Do you know if there are any issues with using both this and Polly?

Is there a best way to do this to make sure they don't interfere with eachother?

Burwin commented 2 years ago

Theoretically, it should work. I haven't tested this at all yet, but I intend to eventually. Unofficially supporting the use of Polly and RestSharp is a high priority for me once the core HallPass itself is hardened a bit more.

As of now, I'd think the best way to use Polly with HallPass would be to just wrap your usage of HttpClient within a Polly RetryPolicy.

Pseudo-code (haven't checked the Polly docs before writing this out):

var myRetryPolicy = Policy.Retry(...);
myRetryPolicy.Execute(async () => {
    var httpClient = _httpClientFactory.CreateClient(); // or CreateHallPassClient()
    var response = await httpClient.SendAsync(myRequest);
    ...
});

Let me know if that doesn't make sense. And if you try it, please let me know how it goes.