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

@ -6,9 +6,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Failsafe" Version="1.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<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.Settings" Version="1.3.4" />
</ItemGroup>

Loading…
Cancel
Save