27 lines
873 B
C#
27 lines
873 B
C#
using DeepL;
|
|
using Polly;
|
|
using Polly.Retry;
|
|
|
|
namespace FictionArchive.Service.TranslationService.Services.Resilience;
|
|
|
|
public static class TranslationResiliencePipeline
|
|
{
|
|
public static ResiliencePipeline Build()
|
|
{
|
|
return new ResiliencePipelineBuilder()
|
|
.AddRetry(new RetryStrategyOptions
|
|
{
|
|
ShouldHandle = new PredicateBuilder()
|
|
.Handle<HttpRequestException>()
|
|
.Handle<TaskCanceledException>(ex => ex.InnerException is TimeoutException)
|
|
.Handle<ConnectionException>()
|
|
.Handle<TooManyRequestsException>(),
|
|
MaxRetryAttempts = 3,
|
|
BackoffType = DelayBackoffType.Exponential,
|
|
Delay = TimeSpan.FromMilliseconds(500),
|
|
UseJitter = true
|
|
})
|
|
.Build();
|
|
}
|
|
}
|