Skip to content

Commit

Permalink
Merge pull request #68 from stebet/host-fix-retries
Browse files Browse the repository at this point in the history
Fixing retries
  • Loading branch information
stebet authored May 29, 2024
2 parents b3d7e61 + 472d561 commit d64ffb2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/HaveIBeenPwned.PwnedPasswords.Downloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
IHttpClientBuilder clientBuilder = services.AddHttpClient("PwnedPasswords");
clientBuilder.AddResilienceHandler("retry", b =>
{
b.AddRetry(new RetryStrategyOptions<HttpResponseMessage> { MaxRetryAttempts = 10, OnRetry = OnRequestErrorAsync });
b.AddRetry(new RetryStrategyOptions<HttpResponseMessage> { MaxRetryAttempts = 10, OnRetry = OnRequestErrorAsync, ShouldHandle = ShouldHandle });
});
clientBuilder.ConfigurePrimaryHttpMessageHandler(() =>
{
Expand Down Expand Up @@ -78,6 +78,7 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
#endif
});
});
static ValueTask<bool> ShouldHandle(RetryPredicateArguments<HttpResponseMessage> predicate) => ValueTask.FromResult((predicate.Outcome.Result?.IsSuccessStatusCode ?? false) != true);

static ValueTask OnRequestErrorAsync(OnRetryArguments<HttpResponseMessage> args)
{
Expand Down

0 comments on commit d64ffb2

Please sign in to comment.