diff --git a/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs index 5fc2728b8..3b8874c6b 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadServiceFixture.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Core.Test.Download .Returns(_downloadClients); Mocker.GetMock() - .Setup(v => v.GetDownloadClient(It.IsAny(), It.IsAny())) + .Setup(v => v.GetDownloadClient(It.IsAny(), It.IsAny(), It.IsAny())) .Returns((v, i) => _downloadClients.FirstOrDefault(d => d.Protocol == v)); var releaseInfo = Builder.CreateNew() diff --git a/src/NzbDrone.Core/Download/DownloadClientProvider.cs b/src/NzbDrone.Core/Download/DownloadClientProvider.cs index df9249dcc..370b66dea 100644 --- a/src/NzbDrone.Core/Download/DownloadClientProvider.cs +++ b/src/NzbDrone.Core/Download/DownloadClientProvider.cs @@ -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 GetDownloadClients(bool filterBlockedClients = false); IDownloadClient Get(int id); } @@ -35,8 +35,9 @@ namespace NzbDrone.Core.Download _lastUsedDownloadClient = cacheManager.GetCache(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(_downloadClientStatusService.GetBlockedProviders().Select(v => v.ProviderId)); var availableProviders = _downloadClientFactory.GetAvailableProviders().Where(v => v.Protocol == downloadProtocol).ToList(); if (!availableProviders.Any()) @@ -52,12 +53,15 @@ 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"); + } + + return client; } } - var blockedProviders = new HashSet(_downloadClientStatusService.GetBlockedProviders().Select(v => v.ProviderId)); - if (blockedProviders.Any()) { var nonBlockedProviders = availableProviders.Where(v => !blockedProviders.Contains(v.Definition.Id)).ToList(); @@ -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."); diff --git a/src/NzbDrone.Core/Download/DownloadService.cs b/src/NzbDrone.Core/Download/DownloadService.cs index 9fc2ee142..7a9288590 100644 --- a/src/NzbDrone.Core/Download/DownloadService.cs +++ b/src/NzbDrone.Core/Download/DownloadService.cs @@ -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; @@ -53,7 +54,8 @@ namespace NzbDrone.Core.Download Ensure.That(remoteMovie.Movie, () => remoteMovie.Movie).IsNotNull(); var downloadTitle = remoteMovie.Release.Title; - var downloadClient = _downloadClientProvider.GetDownloadClient(remoteMovie.Release.DownloadProtocol, remoteMovie.Release.IndexerId); + var filterBlockedClients = remoteMovie.Release.PendingReleaseReason == PendingReleaseReason.DownloadClientUnavailable; + var downloadClient = _downloadClientProvider.GetDownloadClient(remoteMovie.Release.DownloadProtocol, remoteMovie.Release.IndexerId, filterBlockedClients); if (downloadClient == null) { diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index 85dc44e70..a49e4921c 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -132,7 +132,14 @@ namespace NzbDrone.Core.Download.Pending public List 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()) { diff --git a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs index 404f08c0a..de03449fa 100644 --- a/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs +++ b/src/NzbDrone.Core/Parser/Model/ReleaseInfo.cs @@ -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; @@ -36,6 +38,10 @@ namespace NzbDrone.Core.Parser.Model public IndexerFlags IndexerFlags { get; set; } public List Languages { get; set; } + // Used to track pending releases that are being reprocessed + [JsonIgnore] + public PendingReleaseReason? PendingReleaseReason { get; set; } + public int Age { get { return DateTime.UtcNow.Subtract(PublishDate).Days; }