2020-07-08 14:40:08 +00:00
|
|
|
using System.Linq;
|
2019-06-14 03:54:25 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.Download;
|
2020-07-08 14:40:08 +00:00
|
|
|
using NzbDrone.Core.Localization;
|
2019-06-14 03:54:25 +00:00
|
|
|
using NzbDrone.Core.ThingiProvider.Events;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.HealthCheck.Checks
|
|
|
|
{
|
|
|
|
[CheckOn(typeof(ProviderUpdatedEvent<IDownloadClient>))]
|
|
|
|
[CheckOn(typeof(ProviderDeletedEvent<IDownloadClient>))]
|
|
|
|
[CheckOn(typeof(ProviderStatusChangedEvent<IDownloadClient>))]
|
|
|
|
public class DownloadClientStatusCheck : HealthCheckBase
|
|
|
|
{
|
|
|
|
private readonly IDownloadClientFactory _providerFactory;
|
|
|
|
private readonly IDownloadClientStatusService _providerStatusService;
|
|
|
|
|
2020-07-08 14:40:08 +00:00
|
|
|
public DownloadClientStatusCheck(IDownloadClientFactory providerFactory, IDownloadClientStatusService providerStatusService, ILocalizationService localizationService)
|
|
|
|
: base(localizationService)
|
2019-06-14 03:54:25 +00:00
|
|
|
{
|
|
|
|
_providerFactory = providerFactory;
|
|
|
|
_providerStatusService = providerStatusService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override HealthCheck Check()
|
|
|
|
{
|
|
|
|
var enabledProviders = _providerFactory.GetAvailableProviders();
|
|
|
|
var backOffProviders = enabledProviders.Join(_providerStatusService.GetBlockedProviders(),
|
|
|
|
i => i.Definition.Id,
|
|
|
|
s => s.ProviderId,
|
|
|
|
(i, s) => new { Provider = i, Status = s })
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
if (backOffProviders.Empty())
|
|
|
|
{
|
|
|
|
return new HealthCheck(GetType());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (backOffProviders.Count == enabledProviders.Count)
|
|
|
|
{
|
2021-06-05 19:26:09 +00:00
|
|
|
return new HealthCheck(GetType(), HealthCheckResult.Error, _localizationService.GetLocalizedString("DownloadClientStatusCheckAllClientMessage"), "#download-clients-are-unavailable-due-to-failures");
|
2019-06-14 03:54:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-05 19:26:09 +00:00
|
|
|
return new HealthCheck(GetType(), HealthCheckResult.Warning, string.Format(_localizationService.GetLocalizedString("DownloadClientStatusCheckSingleClientMessage"), string.Join(", ", backOffProviders.Select(v => v.Provider.Definition.Name))), "#download-clients-are-unavailable-due-to-failures");
|
2019-06-14 03:54:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|