From d84222ea09d8cef1b94a27fbbe4a592363fe3e30 Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Sun, 1 Dec 2019 17:53:10 +0200 Subject: [PATCH] Use Polly instead of Failsafe --- DiscordChatExporter.Core.Services/DataService.cs | 13 ++++++------- .../DiscordChatExporter.Core.Services.csproj | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DiscordChatExporter.Core.Services/DataService.cs b/DiscordChatExporter.Core.Services/DataService.cs index 774d1b9c..5c749e68 100644 --- a/DiscordChatExporter.Core.Services/DataService.cs +++ b/DiscordChatExporter.Core.Services/DataService.cs @@ -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(false, e => (int) e.StatusCode >= 500) - .Catch(false, e => (int) e.StatusCode == 429) - .WithMaxTryCount(10) - .WithDelay(TimeSpan.FromSeconds(0.4)); + var retryPolicy = Policy + .Handle(e => (int) e.StatusCode >= 500) + .Or(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"; diff --git a/DiscordChatExporter.Core.Services/DiscordChatExporter.Core.Services.csproj b/DiscordChatExporter.Core.Services/DiscordChatExporter.Core.Services.csproj index 7b9fc036..25f3b226 100644 --- a/DiscordChatExporter.Core.Services/DiscordChatExporter.Core.Services.csproj +++ b/DiscordChatExporter.Core.Services/DiscordChatExporter.Core.Services.csproj @@ -6,9 +6,9 @@ - +