Fixed: Don't retry grabbing the same release if download client is unavailable

Closes #3116
pull/5671/head
Mark McDowall 1 year ago
parent f946d78153
commit b38c1255dc

@ -32,7 +32,7 @@ namespace NzbDrone.Core.Test.Download
.Returns(_downloadClients);
Mocker.GetMock<IProvideDownloadClient>()
.Setup(v => v.GetDownloadClient(It.IsAny<DownloadProtocol>(), It.IsAny<int>()))
.Setup(v => v.GetDownloadClient(It.IsAny<DownloadProtocol>(), It.IsAny<int>(), It.IsAny<bool>()))
.Returns<DownloadProtocol, int>((v, i) => _downloadClients.FirstOrDefault(d => d.Protocol == v));
var episodes = Builder<Episode>.CreateListOfSize(2)

@ -9,7 +9,7 @@ namespace NzbDrone.Core.Download
{
public interface IProvideDownloadClient
{
IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0);
IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false);
IEnumerable<IDownloadClient> GetDownloadClients(bool filterBlockedClients = false);
IDownloadClient Get(int id);
}
@ -35,8 +35,9 @@ namespace NzbDrone.Core.Download
_lastUsedDownloadClient = cacheManager.GetCache<int>(GetType(), "lastDownloadClientId");
}
public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0)
public IDownloadClient GetDownloadClient(DownloadProtocol downloadProtocol, int indexerId = 0, bool filterBlockedClients = false)
{
var blockedProviders = new HashSet<int>(_downloadClientStatusService.GetBlockedProviders().Select(v => v.ProviderId));
var availableProviders = _downloadClientFactory.GetAvailableProviders().Where(v => v.Protocol == downloadProtocol).ToList();
if (!availableProviders.Any())
@ -52,11 +53,14 @@ namespace NzbDrone.Core.Download
{
var client = availableProviders.SingleOrDefault(d => d.Definition.Id == indexer.DownloadClientId);
return client ?? throw new DownloadClientUnavailableException($"Indexer specified download client is not available");
}
if (client == null || (filterBlockedClients && blockedProviders.Contains(client.Definition.Id)))
{
throw new DownloadClientUnavailableException($"Indexer specified download client is not available");
}
var blockedProviders = new HashSet<int>(_downloadClientStatusService.GetBlockedProviders().Select(v => v.ProviderId));
return client;
}
}
if (blockedProviders.Any())
{
@ -66,6 +70,10 @@ namespace NzbDrone.Core.Download
{
availableProviders = nonBlockedProviders;
}
else if (filterBlockedClients)
{
throw new DownloadClientUnavailableException($"All download clients for {downloadProtocol} are not available");
}
else
{
_logger.Trace("No non-blocked Download Client available, retrying blocked one.");

@ -6,6 +6,7 @@ using NzbDrone.Common.Http;
using NzbDrone.Common.Instrumentation.Extensions;
using NzbDrone.Common.TPL;
using NzbDrone.Core.Download.Clients;
using NzbDrone.Core.Download.Pending;
using NzbDrone.Core.Exceptions;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Messaging.Events;
@ -50,9 +51,11 @@ namespace NzbDrone.Core.Download
public void DownloadReport(RemoteEpisode remoteEpisode, int? downloadClientId)
{
var filterBlockedClients = remoteEpisode.Release.PendingReleaseReason == PendingReleaseReason.DownloadClientUnavailable;
var downloadClient = downloadClientId.HasValue
? _downloadClientProvider.Get(downloadClientId.Value)
: _downloadClientProvider.GetDownloadClient(remoteEpisode.Release.DownloadProtocol, remoteEpisode.Release.IndexerId);
: _downloadClientProvider.GetDownloadClient(remoteEpisode.Release.DownloadProtocol, remoteEpisode.Release.IndexerId, filterBlockedClients);
DownloadReport(remoteEpisode, downloadClient);
}

@ -139,7 +139,14 @@ namespace NzbDrone.Core.Download.Pending
public List<ReleaseInfo> GetPending()
{
var releases = _repository.All().Select(p => p.Release).ToList();
var releases = _repository.All().Select(p =>
{
var release = p.Release;
release.PendingReleaseReason = p.Reason;
return release;
}).ToList();
if (releases.Any())
{

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using NzbDrone.Core.Download.Pending;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Languages;
@ -37,6 +39,10 @@ namespace NzbDrone.Core.Parser.Model
public List<Language> Languages { get; set; }
// Used to track pending releases that are being reprocessed
[JsonIgnore]
public PendingReleaseReason? PendingReleaseReason { get; set; }
public int Age
{
get

Loading…
Cancel
Save