mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
feat(api-clients): ✨ add retry to IDirectoryClient transient errors
This commit is contained in:
parent
9c367dbfc6
commit
1f916ccb58
2 changed files with 8 additions and 2 deletions
|
|
@ -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)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue