From 4d4b0135017a9cd860d7ab1f60f78b8fa670ef91 Mon Sep 17 00:00:00 2001 From: John Lambert Date: Thu, 31 Oct 2024 17:09:38 -0400 Subject: [PATCH] Webhook retry (#532) * fix up webhook retry * remove Polly. --- .../Configuration/IServalBuilderExtensions.cs | 9 +------ .../Serval.Webhooks/Serval.Webhooks.csproj | 1 - .../Serval.Webhooks/Services/WebhookJob.cs | 26 +++++++++++++++++++ src/Serval/src/Serval.Webhooks/Usings.cs | 1 - 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/Serval/src/Serval.Webhooks/Configuration/IServalBuilderExtensions.cs b/src/Serval/src/Serval.Webhooks/Configuration/IServalBuilderExtensions.cs index 2c2f8503..383e5baf 100644 --- a/src/Serval/src/Serval.Webhooks/Configuration/IServalBuilderExtensions.cs +++ b/src/Serval/src/Serval.Webhooks/Configuration/IServalBuilderExtensions.cs @@ -4,14 +4,7 @@ public static class IServalBuilderExtensions { public static IServalBuilder AddWebhooks(this IServalBuilder builder) { - builder - .Services.AddHttpClient() - .AddTransientHttpErrorPolicy(b => - b.WaitAndRetryAsync( - 7, - retryAttempt => TimeSpan.FromSeconds(2 * retryAttempt) // total 56, less than the 1 minute limit - ) - ); + builder.Services.AddHttpClient(); builder.Services.AddScoped(); return builder; } diff --git a/src/Serval/src/Serval.Webhooks/Serval.Webhooks.csproj b/src/Serval/src/Serval.Webhooks/Serval.Webhooks.csproj index 44f1ef4d..4f9fa6d8 100644 --- a/src/Serval/src/Serval.Webhooks/Serval.Webhooks.csproj +++ b/src/Serval/src/Serval.Webhooks/Serval.Webhooks.csproj @@ -14,7 +14,6 @@ - diff --git a/src/Serval/src/Serval.Webhooks/Services/WebhookJob.cs b/src/Serval/src/Serval.Webhooks/Services/WebhookJob.cs index faee17d4..384ba6be 100644 --- a/src/Serval/src/Serval.Webhooks/Services/WebhookJob.cs +++ b/src/Serval/src/Serval.Webhooks/Services/WebhookJob.cs @@ -6,6 +6,32 @@ public class WebhookJob(IRepository hooks, HttpClient httpClient, IOpti private readonly HttpClient _httpClient = httpClient; private readonly JsonOptions _jsonOptions = jsonOptions.Value; + [AutomaticRetry( + Attempts = 20, + DelaysInSeconds = new[] + { + 1, + 2, + 4, + 8, + 16, + 32, + 64, + 128, + 256, + 512, + 1024, + 2048, + 2048, + 2048, + 2048, + 2048, + 2048, + 2048, + 2048 + }, + LogEvents = true + )] public async Task RunAsync( WebhookEvent webhookEvent, string owner, diff --git a/src/Serval/src/Serval.Webhooks/Usings.cs b/src/Serval/src/Serval.Webhooks/Usings.cs index f68d9a61..39f9b6a5 100644 --- a/src/Serval/src/Serval.Webhooks/Usings.cs +++ b/src/Serval/src/Serval.Webhooks/Usings.cs @@ -11,7 +11,6 @@ global using Microsoft.AspNetCore.Mvc; global using Microsoft.AspNetCore.Routing; global using Microsoft.Extensions.Options; -global using Polly; global using Serval.Shared.Contracts; global using Serval.Shared.Controllers; global using Serval.Shared.Models;