Use Polly instead of Failsafe

pull/241/head
Alexey Golub 5 years ago
parent cc1bb924e7
commit d84222ea09

@ -7,8 +7,8 @@ using System.Threading.Tasks;
using DiscordChatExporter.Core.Models; using DiscordChatExporter.Core.Models;
using DiscordChatExporter.Core.Services.Exceptions; using DiscordChatExporter.Core.Services.Exceptions;
using DiscordChatExporter.Core.Services.Internal; using DiscordChatExporter.Core.Services.Internal;
using Failsafe;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Polly;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.Core.Services namespace DiscordChatExporter.Core.Services
@ -21,14 +21,13 @@ namespace DiscordChatExporter.Core.Services
params string[] parameters) params string[] parameters)
{ {
// Create retry policy // Create retry policy
var retry = Retry.Create() var retryPolicy = Policy
.Catch<HttpErrorStatusCodeException>(false, e => (int) e.StatusCode >= 500) .Handle<HttpErrorStatusCodeException>(e => (int) e.StatusCode >= 500)
.Catch<HttpErrorStatusCodeException>(false, e => (int) e.StatusCode == 429) .Or<HttpErrorStatusCodeException>(e => (int) e.StatusCode == 429)
.WithMaxTryCount(10) .WaitAndRetryAsync(10, _ => TimeSpan.FromSeconds(3));
.WithDelay(TimeSpan.FromSeconds(0.4));
// Send request // Send request
return await retry.ExecuteAsync(async () => return await retryPolicy.ExecuteAsync(async () =>
{ {
// Create request // Create request
const string apiRoot = "https://discordapp.com/api/v6"; const string apiRoot = "https://discordapp.com/api/v6";

@ -6,9 +6,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Failsafe" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Onova" Version="2.5.1" /> <PackageReference Include="Onova" Version="2.5.1" />
<PackageReference Include="Polly" Version="7.2.0" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" /> <PackageReference Include="Tyrrrz.Extensions" Version="1.6.5" />
<PackageReference Include="Tyrrrz.Settings" Version="1.3.4" /> <PackageReference Include="Tyrrrz.Settings" Version="1.3.4" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save