Skip to content

Commit

Permalink
Webhook retry (#532)
Browse files Browse the repository at this point in the history
* fix up webhook retry

* remove Polly.
  • Loading branch information
johnml1135 authored Oct 31, 2024
1 parent f872bfa commit 4d4b013
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ public static class IServalBuilderExtensions
{
public static IServalBuilder AddWebhooks(this IServalBuilder builder)
{
builder
.Services.AddHttpClient<WebhookJob>()
.AddTransientHttpErrorPolicy(b =>
b.WaitAndRetryAsync(
7,
retryAttempt => TimeSpan.FromSeconds(2 * retryAttempt) // total 56, less than the 1 minute limit
)
);
builder.Services.AddHttpClient<WebhookJob>();
builder.Services.AddScoped<IWebhookService, WebhookService>();
return builder;
}
Expand Down
1 change: 0 additions & 1 deletion src/Serval/src/Serval.Webhooks/Serval.Webhooks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<PackageReference Include="Asp.Versioning.Abstractions" Version="6.2.1" />
<PackageReference Include="Hangfire.Core" Version="1.8.14" />
<PackageReference Include="MassTransit" Version="8.0.14" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
</ItemGroup>

<ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions src/Serval/src/Serval.Webhooks/Services/WebhookJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ public class WebhookJob(IRepository<Webhook> 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,
Expand Down
1 change: 0 additions & 1 deletion src/Serval/src/Serval.Webhooks/Usings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4d4b013

Please sign in to comment.