mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-18 08:19:38 +02:00
New: Retry on failed downloads of torrent and nzb files
(cherry picked from commit bc20ef73bdd47b7cdad43d4c7d4b4bd534e49252) Closes #9528
This commit is contained in:
parent
5d7e23092f
commit
e29717ec6c
@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using FluentValidation.Results;
|
using FluentValidation.Results;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
|
using NzbDrone.Common.Http;
|
||||||
using NzbDrone.Core.Configuration;
|
using NzbDrone.Core.Configuration;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
using NzbDrone.Core.Organizer;
|
using NzbDrone.Core.Organizer;
|
||||||
@ -11,6 +13,8 @@
|
|||||||
using NzbDrone.Core.RemotePathMappings;
|
using NzbDrone.Core.RemotePathMappings;
|
||||||
using NzbDrone.Core.ThingiProvider;
|
using NzbDrone.Core.ThingiProvider;
|
||||||
using NzbDrone.Core.Validation;
|
using NzbDrone.Core.Validation;
|
||||||
|
using Polly;
|
||||||
|
using Polly.Retry;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Download
|
namespace NzbDrone.Core.Download
|
||||||
{
|
{
|
||||||
@ -23,6 +27,37 @@ public abstract class DownloadClientBase<TSettings> : IDownloadClient
|
|||||||
protected readonly IRemotePathMappingService _remotePathMappingService;
|
protected readonly IRemotePathMappingService _remotePathMappingService;
|
||||||
protected readonly Logger _logger;
|
protected readonly Logger _logger;
|
||||||
|
|
||||||
|
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 = TimeSpan.FromSeconds(3),
|
||||||
|
MaxRetryAttempts = 2,
|
||||||
|
BackoffType = DelayBackoffType.Exponential,
|
||||||
|
UseJitter = true,
|
||||||
|
OnRetry = args =>
|
||||||
|
{
|
||||||
|
var exception = args.Outcome.Exception;
|
||||||
|
|
||||||
|
if (exception is not null)
|
||||||
|
{
|
||||||
|
_logger.Info(exception, "Request for {0} failed with exception '{1}'. Retrying in {2}s.", Definition.Name, exception.Message, args.RetryDelay.TotalSeconds);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.Info("Request for {0} failed with status {1}. Retrying in {2}s.", Definition.Name, args.Outcome.Result?.StatusCode, args.RetryDelay.TotalSeconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
|
||||||
public abstract string Name { get; }
|
public abstract string Name { get; }
|
||||||
|
|
||||||
public Type ConfigContract => typeof(TSettings);
|
public Type ConfigContract => typeof(TSettings);
|
||||||
@ -58,10 +93,7 @@ public override string ToString()
|
|||||||
return GetType().Name;
|
return GetType().Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract DownloadProtocol Protocol
|
public abstract DownloadProtocol Protocol { get; }
|
||||||
{
|
|
||||||
get;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Task<string> Download(RemoteMovie remoteMovie, IIndexer indexer);
|
public abstract Task<string> Download(RemoteMovie remoteMovie, IIndexer indexer);
|
||||||
public abstract IEnumerable<DownloadClientItem> GetItems();
|
public abstract IEnumerable<DownloadClientItem> GetItems();
|
||||||
|
@ -134,7 +134,9 @@ private async Task<string> DownloadFromWebUrl(RemoteMovie remoteMovie, IIndexer
|
|||||||
request.Headers.Accept = "application/x-bittorrent";
|
request.Headers.Accept = "application/x-bittorrent";
|
||||||
request.AllowAutoRedirect = false;
|
request.AllowAutoRedirect = false;
|
||||||
|
|
||||||
var response = await _httpClient.GetAsync(request);
|
var response = await RetryStrategy
|
||||||
|
.ExecuteAsync(static async (state, _) => await state._httpClient.GetAsync(state.request), (_httpClient, request))
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
if (response.StatusCode == HttpStatusCode.MovedPermanently ||
|
if (response.StatusCode == HttpStatusCode.MovedPermanently ||
|
||||||
response.StatusCode == HttpStatusCode.Found ||
|
response.StatusCode == HttpStatusCode.Found ||
|
||||||
|
@ -48,7 +48,9 @@ public override async Task<string> Download(RemoteMovie remoteMovie, IIndexer in
|
|||||||
var request = indexer?.GetDownloadRequest(url) ?? new HttpRequest(url);
|
var request = indexer?.GetDownloadRequest(url) ?? new HttpRequest(url);
|
||||||
request.RateLimitKey = remoteMovie?.Release?.IndexerId.ToString();
|
request.RateLimitKey = remoteMovie?.Release?.IndexerId.ToString();
|
||||||
|
|
||||||
var response = await _httpClient.GetAsync(request);
|
var response = await RetryStrategy
|
||||||
|
.ExecuteAsync(static async (state, _) => await state._httpClient.GetAsync(state.request), (_httpClient, request))
|
||||||
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
nzbData = response.ResponseData;
|
nzbData = response.ResponseData;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
<PackageReference Include="Equ" Version="2.3.0" />
|
<PackageReference Include="Equ" Version="2.3.0" />
|
||||||
<PackageReference Include="MailKit" Version="3.6.0" />
|
<PackageReference Include="MailKit" Version="3.6.0" />
|
||||||
<PackageReference Include="Npgsql" Version="7.0.6" />
|
<PackageReference Include="Npgsql" Version="7.0.6" />
|
||||||
|
<PackageReference Include="Polly" Version="8.2.0" />
|
||||||
<PackageReference Include="Servarr.FFMpegCore" Version="4.7.0-26" />
|
<PackageReference Include="Servarr.FFMpegCore" Version="4.7.0-26" />
|
||||||
<PackageReference Include="Servarr.FFprobe" Version="5.1.4.112" />
|
<PackageReference Include="Servarr.FFprobe" Version="5.1.4.112" />
|
||||||
<PackageReference Include="System.Memory" Version="4.5.5" />
|
<PackageReference Include="System.Memory" Version="4.5.5" />
|
||||||
|
Loading…
Reference in New Issue
Block a user