From be4d70e3a9362baa14871c3eacb0371492a129f0 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 28 Feb 2017 00:12:22 -0800 Subject: [PATCH] Fixed: Health check failing and preventing others from running --- .../Checks/ImportMechanismCheck.cs | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/NzbDrone.Core/HealthCheck/Checks/ImportMechanismCheck.cs b/src/NzbDrone.Core/HealthCheck/Checks/ImportMechanismCheck.cs index 373d47bfb..ec35653c7 100644 --- a/src/NzbDrone.Core/HealthCheck/Checks/ImportMechanismCheck.cs +++ b/src/NzbDrone.Core/HealthCheck/Checks/ImportMechanismCheck.cs @@ -1,7 +1,10 @@ -using System.Linq; +using System; +using System.Collections.Generic; +using System.Linq; using NzbDrone.Common.Disk; using NzbDrone.Core.Configuration; using NzbDrone.Core.Download; +using NzbDrone.Core.Download.Clients; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; @@ -22,11 +25,26 @@ public ImportMechanismCheck(IConfigService configService, IProvideDownloadClient public override HealthCheck Check() { var droneFactoryFolder = new OsPath(_configService.DownloadedEpisodesFolder); - var downloadClients = _provideDownloadClient.GetDownloadClients().Select(v => new { downloadClient = v, status = v.GetStatus() }).ToList(); + List downloadClients; - var downloadClientIsLocalHost = downloadClients.All(v => v.status.IsLocalhost); - var downloadClientOutputInDroneFactory = !droneFactoryFolder.IsEmpty - && downloadClients.Any(v => v.status.OutputRootFolders != null && v.status.OutputRootFolders.Any(droneFactoryFolder.Contains)); + try + { + downloadClients = _provideDownloadClient.GetDownloadClients().Select(v => new ImportMechanismCheckStatus + { + DownloadClient = v, + Status = v.GetStatus() + }).ToList(); + } + catch (DownloadClientException) + { + // One or more download clients failed, assume the health is okay and verify later + return new HealthCheck(GetType()); + } + + var downloadClientIsLocalHost = downloadClients.All(v => v.Status.IsLocalhost); + var downloadClientOutputInDroneFactory = !droneFactoryFolder.IsEmpty && + downloadClients.Any(v => v.Status.OutputRootFolders != null && + v.Status.OutputRootFolders.Any(droneFactoryFolder.Contains)); if (!_configService.IsDefined("EnableCompletedDownloadHandling")) { @@ -36,7 +54,7 @@ public override HealthCheck Check() return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Multi-Computer unsupported)", "Migrating-to-Completed-Download-Handling#Unsupported-download-client-on-different-computer"); } - if (downloadClients.All(v => v.downloadClient is Sabnzbd)) + if (downloadClients.All(v => v.DownloadClient is Sabnzbd)) { // With Sabnzbd we can check if the category should be changed. if (downloadClientOutputInDroneFactory) @@ -46,7 +64,8 @@ public override HealthCheck Check() return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Sabnzbd)", "Migrating-to-Completed-Download-Handling#sabnzbd-enable-completed-download-handling"); } - if (downloadClients.All(v => v.downloadClient is Nzbget)) + + if (downloadClients.All(v => v.DownloadClient is Nzbget)) { // With Nzbget we can check if the category should be changed. if (downloadClientOutputInDroneFactory) @@ -56,6 +75,7 @@ public override HealthCheck Check() return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible (Nzbget)", "Migrating-to-Completed-Download-Handling#nzbget-enable-completed-download-handling"); } + return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling if possible", "Migrating-to-Completed-Download-Handling"); } @@ -64,8 +84,13 @@ public override HealthCheck Check() return new HealthCheck(GetType(), HealthCheckResult.Warning, "Enable Completed Download Handling or configure Drone factory"); } - return new HealthCheck(GetType()); } } + + public class ImportMechanismCheckStatus + { + public IDownloadClient DownloadClient { get; set; } + public DownloadClientStatus Status { get; set; } + } }