Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook retry #532

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading