Added mechanism for package maintainers to produce a health check error.

This commit is contained in:
Taloth Saldono 2021-03-06 22:47:02 +01:00
parent 79cfa3a5f6
commit 7da02c236a
5 changed files with 63 additions and 6 deletions

View File

@ -21,14 +21,14 @@ namespace NzbDrone.Core.Test.UpdateTests
public void no_update_when_version_higher()
{
UseRealHttp();
Subject.GetLatestUpdate("master", new Version(10, 0)).Should().BeNull();
Subject.GetLatestUpdate("main", new Version(10, 0)).Should().BeNull();
}
[Test]
public void finds_update_when_version_lower()
{
UseRealHttp();
Subject.GetLatestUpdate("master", new Version(3, 0)).Should().NotBeNull();
Subject.GetLatestUpdate("main", new Version(3, 0)).Should().NotBeNull();
}
[Test]

View File

@ -177,7 +177,7 @@ namespace NzbDrone.Core.Configuration
public bool AnalyticsEnabled => GetValueBoolean("AnalyticsEnabled", true, persist: false);
public string Branch => GetValue("Branch", "master").ToLowerInvariant();
public string Branch => GetValue("Branch", "main").ToLowerInvariant();
public string LogLevel => GetValue("LogLevel", "info");
public string ConsoleLogLevel => GetValue("ConsoleLogLevel", string.Empty, persist: false);

View File

@ -16,6 +16,7 @@ namespace NzbDrone.Core.Configuration
{
string PackageVersion { get; }
string PackageAuthor { get; }
string PackageGlobalMessage { get; }
string PackageBranch { get; }
UpdateMechanism PackageUpdateMechanism { get; }
string PackageUpdateMechanismMessage { get; }
@ -37,7 +38,7 @@ namespace NzbDrone.Core.Configuration
var releaseInfoPath = Path.Combine(bin, "release_info");
PackageUpdateMechanism = UpdateMechanism.BuiltIn;
DefaultBranch = "master";
DefaultBranch = "main";
if (Path.GetFileName(bin) == "bin" && diskProvider.FileExists(packageInfoPath))
{
@ -45,6 +46,7 @@ namespace NzbDrone.Core.Configuration
PackageVersion = ReadValue(data, "PackageVersion");
PackageAuthor = ReadValue(data, "PackageAuthor");
PackageGlobalMessage = ReadValue(data, "PackageGlobalMessage");
PackageUpdateMechanism = ReadEnumValue(data, "UpdateMethod", UpdateMechanism.BuiltIn);
PackageUpdateMechanismMessage = ReadValue(data, "UpdateMethodMessage");
PackageBranch = ReadValue(data, "Branch");
@ -98,6 +100,7 @@ namespace NzbDrone.Core.Configuration
public string PackageVersion { get; private set; }
public string PackageAuthor { get; private set; }
public string PackageGlobalMessage { get; private set; }
public string PackageBranch { get; private set; }
public UpdateMechanism PackageUpdateMechanism { get; private set; }
public string PackageUpdateMechanismMessage { get; private set; }

View File

@ -0,0 +1,46 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
using NLog;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Download;
using NzbDrone.Core.ThingiProvider.Events;
namespace NzbDrone.Core.HealthCheck.Checks
{
public class PackageGlobalMessageCheck : HealthCheckBase
{
private readonly IDeploymentInfoProvider _deploymentInfoProvider;
public PackageGlobalMessageCheck(IDeploymentInfoProvider deploymentInfoProvider)
{
_deploymentInfoProvider = deploymentInfoProvider;
}
public override HealthCheck Check()
{
if (_deploymentInfoProvider.PackageGlobalMessage.IsNullOrWhiteSpace())
{
return new HealthCheck(GetType());
}
var message = _deploymentInfoProvider.PackageGlobalMessage;
HealthCheckResult result = HealthCheckResult.Notice;
if (message.StartsWith("Error:"))
{
message = message.Substring(6);
result = HealthCheckResult.Error;
}
else if (message.StartsWith("Warn:"))
{
message = message.Substring(5);
result = HealthCheckResult.Warning;
}
return new HealthCheck(GetType(), result, message, "#package_maintainer_message");
}
}
}

View File

@ -143,10 +143,18 @@ namespace NzbDrone.Core.Update
_logger.Info("Preparing client");
_diskTransferService.TransferFolder(_appFolderInfo.GetUpdateClientFolder(), updateSandboxFolder, TransferMode.Move);
_logger.Info("Starting update client {0}", _appFolderInfo.GetUpdateClientExePath());
var updateClientExePath = _appFolderInfo.GetUpdateClientExePath();
if (!_diskProvider.FileExists(updateClientExePath))
{
_logger.Warn("Update client {0} does not exist, aborting update.", updateClientExePath);
return false;
}
_logger.Info("Starting update client {0}", updateClientExePath);
_logger.ProgressInfo("Sonarr will restart shortly.");
_processProvider.Start(_appFolderInfo.GetUpdateClientExePath(), GetUpdaterArgs(updateSandboxFolder));
_processProvider.Start(updateClientExePath, GetUpdaterArgs(updateSandboxFolder));
return true;
}