From 5664054f9550ca50c838f3b04910bf1be84e7430 Mon Sep 17 00:00:00 2001 From: Qstick Date: Mon, 16 Jan 2023 22:38:05 -0600 Subject: [PATCH] Fixed: DownloadClientRootFolderCheck Improvements --- .../Download/DownloadClientProvider.cs | 31 +++++++++++++++++-- .../Checks/DownloadClientRootFolderCheck.cs | 9 +++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/NzbDrone.Core/Download/DownloadClientProvider.cs b/src/NzbDrone.Core/Download/DownloadClientProvider.cs index fb321d8b5..f6d7d2e07 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); - IEnumerable GetDownloadClients(); + IEnumerable GetDownloadClients(bool filterBlockedClients = false); IDownloadClient Get(int id); } @@ -67,14 +67,39 @@ namespace NzbDrone.Core.Download return provider; } - public IEnumerable GetDownloadClients() + public IEnumerable GetDownloadClients(bool filterBlockedClients = false) { - return _downloadClientFactory.GetAvailableProviders(); + var enabledClients = _downloadClientFactory.GetAvailableProviders(); + + if (filterBlockedClients) + { + return FilterBlockedIndexers(enabledClients).ToList(); + } + + return enabledClients; } public IDownloadClient Get(int id) { return _downloadClientFactory.GetAvailableProviders().Single(d => d.Definition.Id == id); } + + private IEnumerable FilterBlockedIndexers(IEnumerable clients) + { + var blockedClients = _downloadClientStatusService.GetBlockedProviders().ToDictionary(v => v.ProviderId, v => v); + + foreach (var client in clients) + { + DownloadClientStatus blockedClientStatus; + + if (blockedClients.TryGetValue(client.Definition.Id, out blockedClientStatus)) + { + _logger.Debug("Temporarily ignoring client {0} till {1} due to recent failures.", client.Definition.Name, blockedClientStatus.DisabledTill.Value.ToLocalTime()); + continue; + } + + yield return client; + } + } } } diff --git a/src/NzbDrone.Core/HealthCheck/Checks/DownloadClientRootFolderCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/DownloadClientRootFolderCheck.cs index 2b0f2f71a..ae9813567 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/DownloadClientRootFolderCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/DownloadClientRootFolderCheck.cs @@ -1,5 +1,6 @@ using System; using System.Linq; +using System.Net.Http; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.Datastore.Events; @@ -37,7 +38,9 @@ namespace NzbDrone.Core.HealthCheck.Checks public override HealthCheck Check() { - var clients = _downloadClientProvider.GetDownloadClients(); + // Only check clients not in failure status, those get another message + var clients = _downloadClientProvider.GetDownloadClients(true); + var rootFolders = _rootFolderService.All(); foreach (var client in clients) @@ -58,6 +61,10 @@ namespace NzbDrone.Core.HealthCheck.Checks { _logger.Debug(ex, "Unable to communicate with {0}", client.Definition.Name); } + catch (HttpRequestException ex) + { + _logger.Debug(ex, "Unable to communicate with {0}", client.Definition.Name); + } catch (Exception ex) { _logger.Error(ex, "Unknown error occured in DownloadClientRootFolderCheck HealthCheck");