feat(api-clients): add retry to IDirectoryClient transient errors

This commit is contained in:
Collin M. Barrett 2020-09-17 18:08:25 -05:00
parent 9c367dbfc6
commit 1f916ccb58
2 changed files with 8 additions and 2 deletions

View file

@ -2,6 +2,7 @@
using FilterLists.SharedKernel.Apis.Clients.Options;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using Refit;
namespace FilterLists.SharedKernel.Apis.Clients
@ -10,14 +11,18 @@ public static class ConfigurationExtensions
{
public static void AddApiClients(this IServiceCollection services, IConfiguration configuration)
{
// TODO: add Polly for resiliency
// TODO: use SystemTextJsonContentSerializer() once less feature-limited
services.AddRefitClient<IDirectoryApi>()
.ConfigureHttpClient(c =>
{
var host = configuration.GetSection(ApiOptions.Key).Get<ApiOptions>().DirectoryHost;
c.BaseAddress = new UriBuilder("http", host).Uri;
});
})
.AddTransientHttpErrorPolicy(b =>
b.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10)
}));
}
}
}

View file

@ -21,6 +21,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="3.1.8" />
<PackageReference Include="Refit.HttpClientFactory" Version="5.2.1" />
</ItemGroup>