mirror of
https://github.com/Prowlarr/Prowlarr
synced 2026-01-06 07:47:17 +01:00
New: Retry on failed indexer requests
This commit is contained in:
parent
1a894ac583
commit
8af6ea1d8f
2 changed files with 38 additions and 1 deletions
|
|
@ -18,6 +18,8 @@
|
|||
using NzbDrone.Core.IndexerSearch.Definitions;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Parser.Model;
|
||||
using Polly;
|
||||
using Polly.Retry;
|
||||
|
||||
namespace NzbDrone.Core.Indexers
|
||||
{
|
||||
|
|
@ -28,6 +30,38 @@ public abstract class HttpIndexerBase<TSettings> : IndexerBase<TSettings>
|
|||
|
||||
protected readonly IIndexerHttpClient _httpClient;
|
||||
protected readonly IEventAggregator _eventAggregator;
|
||||
|
||||
protected ResiliencePipeline<HttpResponse> RetryStrategy => new ResiliencePipelineBuilder<HttpResponse>()
|
||||
.AddRetry(new RetryStrategyOptions<HttpResponse>
|
||||
{
|
||||
ShouldHandle = static args => args.Outcome switch
|
||||
{
|
||||
{ Result.HasHttpServerError: true } => PredicateResult.True(),
|
||||
{ Result.StatusCode: HttpStatusCode.RequestTimeout } => PredicateResult.True(),
|
||||
_ => PredicateResult.False()
|
||||
},
|
||||
Delay = RateLimit,
|
||||
MaxRetryAttempts = 2,
|
||||
BackoffType = DelayBackoffType.Exponential,
|
||||
UseJitter = true,
|
||||
OnRetry = args =>
|
||||
{
|
||||
var exception = args.Outcome.Exception;
|
||||
|
||||
if (exception is not null)
|
||||
{
|
||||
_logger.Warn(exception, "Request for {0} failed with exception '{1}'. Retrying in {2}s.", Definition.Name, exception.Message, args.RetryDelay.TotalSeconds);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warn("Request for {0} failed with status {1}. Retrying in {2}s.", Definition.Name, args.Outcome.Result?.StatusCode, args.RetryDelay.TotalSeconds);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
})
|
||||
.Build();
|
||||
|
||||
public IDictionary<string, string> Cookies { get; set; }
|
||||
|
||||
public override bool SupportsRss => true;
|
||||
|
|
@ -584,7 +618,9 @@ protected virtual async Task<IndexerResponse> FetchIndexerResponse(IndexerReques
|
|||
request.HttpRequest.SuppressHttpError = true;
|
||||
request.HttpRequest.Encoding ??= Encoding;
|
||||
|
||||
var response = await _httpClient.ExecuteProxiedAsync(request.HttpRequest, Definition);
|
||||
var response = await RetryStrategy
|
||||
.ExecuteAsync(static async (state, _) => await state._httpClient.ExecuteProxiedAsync(state.HttpRequest, state.Definition), (_httpClient, request.HttpRequest, Definition))
|
||||
.ConfigureAwait(false);
|
||||
|
||||
// Check response to see if auth is needed, if needed try again
|
||||
if (CheckIfLoginNeeded(response))
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
|
||||
<PackageReference Include="NLog.Targets.Syslog" Version="7.0.0" />
|
||||
<PackageReference Include="Npgsql" Version="7.0.6" />
|
||||
<PackageReference Include="Polly" Version="8.3.1" />
|
||||
<PackageReference Include="Servarr.FluentMigrator.Runner" Version="3.3.2.9" />
|
||||
<PackageReference Include="Servarr.FluentMigrator.Runner.Postgres" Version="3.3.2.9" />
|
||||
<PackageReference Include="Servarr.FluentMigrator.Runner.SQLite" Version="3.3.2.9" />
|
||||
|
|
|
|||
Loading…
Reference in a new issue