Skip to content

Commit

Permalink
Fixed: Don't call for server notifications on event driven check
Browse files Browse the repository at this point in the history
  • Loading branch information
Qstick committed Jul 17, 2022
1 parent c7e8f51 commit 1d73d25
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
13 changes: 8 additions & 5 deletions src/NzbDrone.Core/HealthCheck/HealthCheckService.cs
Expand Up @@ -77,7 +77,7 @@ public List<HealthCheck> Results()
.ToDictionary(g => g.Key, g => g.ToArray());
}

private void PerformHealthCheck(IProvideHealthCheck[] healthChecks, IEvent message = null)
private void PerformHealthCheck(IProvideHealthCheck[] healthChecks, IEvent message = null, bool performServerChecks = false)
{
var results = new List<HealthCheck>();

Expand All @@ -93,7 +93,10 @@ private void PerformHealthCheck(IProvideHealthCheck[] healthChecks, IEvent messa
}
}

results.AddRange(_serverSideNotificationService.GetServerChecks());
if (performServerChecks)
{
results.AddRange(_serverSideNotificationService.GetServerChecks());
}

foreach (var result in results)
{
Expand All @@ -119,17 +122,17 @@ public void Execute(CheckHealthCommand message)
{
if (message.Trigger == CommandTrigger.Manual)
{
PerformHealthCheck(_healthChecks);
PerformHealthCheck(_healthChecks, null, true);
}
else
{
PerformHealthCheck(_scheduledHealthChecks);
PerformHealthCheck(_scheduledHealthChecks, null, true);
}
}

public void HandleAsync(ApplicationStartedEvent message)
{
PerformHealthCheck(_startupHealthChecks);
PerformHealthCheck(_startupHealthChecks, null, true);
}

public void HandleAsync(IEvent message)
Expand Down
30 changes: 22 additions & 8 deletions src/NzbDrone.Core/HealthCheck/ServerSideNotificationService.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Common.Cloud;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Common.Http;
Expand All @@ -23,24 +24,37 @@ public class ServerSideNotificationService : IServerSideNotificationService
private readonly IHttpRequestBuilderFactory _cloudRequestBuilder;
private readonly Logger _logger;

public ServerSideNotificationService(IHttpClient client, IConfigFileProvider configFileProvider, ILidarrCloudRequestBuilder cloudRequestBuilder, Logger logger)
private readonly ICached<List<HealthCheck>> _cache;

public ServerSideNotificationService(IHttpClient client,
IConfigFileProvider configFileProvider,
ILidarrCloudRequestBuilder cloudRequestBuilder,
ICacheManager cacheManager,
Logger logger)
{
_client = client;
_configFileProvider = configFileProvider;
_cloudRequestBuilder = cloudRequestBuilder.Services;
_logger = logger;

_cache = cacheManager.GetCache<List<HealthCheck>>(GetType());
}

public List<HealthCheck> GetServerChecks()
{
return _cache.Get("ServerChecks", () => RetrieveServerChecks(), TimeSpan.FromHours(2));
}

private List<HealthCheck> RetrieveServerChecks()
{
var request = _cloudRequestBuilder.Create()
.Resource("/notification")
.AddQueryParam("version", BuildInfo.Version)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
.AddQueryParam("branch", _configFileProvider.Branch)
.Build();
.Resource("/notification")
.AddQueryParam("version", BuildInfo.Version)
.AddQueryParam("os", OsInfo.Os.ToString().ToLowerInvariant())
.AddQueryParam("arch", RuntimeInformation.OSArchitecture)
.AddQueryParam("runtime", PlatformInfo.Platform.ToString().ToLowerInvariant())
.AddQueryParam("branch", _configFileProvider.Branch)
.Build();
try
{
_logger.Trace("Getting server side health notifications");
Expand Down

0 comments on commit 1d73d25

Please sign in to comment.