From c2761ef16cc7457be3c147cb356db44aea64f510 Mon Sep 17 00:00:00 2001 From: Qstick Date: Thu, 23 Apr 2020 18:37:21 -0400 Subject: [PATCH] Fixed: Don't lock command queue if updating is disabled --- src/NzbDrone.Core/Jobs/TaskManager.cs | 2 +- .../Commands/ApplicationCheckUpdateCommand.cs | 11 +++ .../Update/InstallUpdateService.cs | 70 ++++++++++++------- 3 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 src/NzbDrone.Core/Update/Commands/ApplicationCheckUpdateCommand.cs diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index 0420e3621..e147d1e13 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -73,7 +73,7 @@ public void Handle(ApplicationStartedEvent message) { new ScheduledTask { Interval = 1 * 60, TypeName = typeof(PreDBSyncCommand).FullName }, new ScheduledTask { Interval = 5, TypeName = typeof(MessagingCleanupCommand).FullName }, - new ScheduledTask { Interval = updateInterval, TypeName = typeof(ApplicationUpdateCommand).FullName }, + new ScheduledTask { Interval = updateInterval, TypeName = typeof(ApplicationCheckUpdateCommand).FullName }, // new ScheduledTask { Interval = 3 * 60, TypeName = typeof(UpdateSceneMappingCommand).FullName }, new ScheduledTask { Interval = 6 * 60, TypeName = typeof(CheckHealthCommand).FullName }, diff --git a/src/NzbDrone.Core/Update/Commands/ApplicationCheckUpdateCommand.cs b/src/NzbDrone.Core/Update/Commands/ApplicationCheckUpdateCommand.cs new file mode 100644 index 000000000..6987af3fa --- /dev/null +++ b/src/NzbDrone.Core/Update/Commands/ApplicationCheckUpdateCommand.cs @@ -0,0 +1,11 @@ +using NzbDrone.Core.Messaging.Commands; + +namespace NzbDrone.Core.Update.Commands +{ + public class ApplicationCheckUpdateCommand : Command + { + public override bool SendUpdatesToClient => true; + + public override string CompletionMessage => null; + } +} diff --git a/src/NzbDrone.Core/Update/InstallUpdateService.cs b/src/NzbDrone.Core/Update/InstallUpdateService.cs index 413bf718f..c0adb851c 100644 --- a/src/NzbDrone.Core/Update/InstallUpdateService.cs +++ b/src/NzbDrone.Core/Update/InstallUpdateService.cs @@ -16,12 +16,12 @@ namespace NzbDrone.Core.Update { - public class InstallUpdateService : IExecute + public class InstallUpdateService : IExecute, IExecute { private readonly ICheckUpdateService _checkUpdateService; private readonly Logger _logger; private readonly IAppFolderInfo _appFolderInfo; - + private readonly IManageCommandQueue _commandQueueManager; private readonly IDiskProvider _diskProvider; private readonly IDiskTransferService _diskTransferService; private readonly IHttpClient _httpClient; @@ -37,6 +37,7 @@ public class InstallUpdateService : IExecute public InstallUpdateService(ICheckUpdateService checkUpdateService, IAppFolderInfo appFolderInfo, + IManageCommandQueue commandQueueManager, IDiskProvider diskProvider, IDiskTransferService diskTransferService, IHttpClient httpClient, @@ -58,6 +59,7 @@ public InstallUpdateService(ICheckUpdateService checkUpdateService, _checkUpdateService = checkUpdateService; _appFolderInfo = appFolderInfo; + _commandQueueManager = commandQueueManager; _diskProvider = diskProvider; _diskTransferService = diskTransferService; _httpClient = httpClient; @@ -209,7 +211,7 @@ private void EnsureAppDataSafety() } } - public void Execute(ApplicationUpdateCommand message) + private UpdatePackage GetUpdatePackage(CommandTrigger updateTrigger) { _logger.ProgressDebug("Checking for updates"); @@ -218,52 +220,70 @@ public void Execute(ApplicationUpdateCommand message) if (latestAvailable == null) { _logger.ProgressDebug("No update available"); - return; + return null; } if (_osInfo.IsDocker) { _logger.ProgressDebug("Updating is disabled inside a docker container. Please update the container image."); - return; + return null; } - if (OsInfo.IsNotWindows && !_configFileProvider.UpdateAutomatically && message.Trigger != CommandTrigger.Manual) + if (OsInfo.IsNotWindows && !_configFileProvider.UpdateAutomatically && updateTrigger != CommandTrigger.Manual) { _logger.ProgressDebug("Auto-update not enabled, not installing available update."); - return; + return null; } // Safety net, ConfigureUpdateMechanism should take care of invalid settings if (_configFileProvider.UpdateMechanism == UpdateMechanism.BuiltIn && _deploymentInfoProvider.IsExternalUpdateMechanism) { _logger.ProgressDebug("Built-In updater disabled, please use {0} to install", _deploymentInfoProvider.PackageUpdateMechanism); - return; + return null; } else if (_configFileProvider.UpdateMechanism != UpdateMechanism.Script && _deploymentInfoProvider.IsExternalUpdateMechanism) { _logger.ProgressDebug("Update available, please use {0} to install", _deploymentInfoProvider.PackageUpdateMechanism); - return; + return null; } - try + return latestAvailable; + } + + public void Execute(ApplicationCheckUpdateCommand message) + { + if (GetUpdatePackage(message.Trigger) != null) { - InstallUpdate(latestAvailable); - _logger.ProgressDebug("Restarting Radarr to apply updates"); + _commandQueueManager.Push(new ApplicationUpdateCommand(), trigger: message.Trigger); } - catch (UpdateFolderNotWritableException ex) + } + + public void Execute(ApplicationUpdateCommand message) + { + var latestAvailable = GetUpdatePackage(message.Trigger); + + if (latestAvailable != null) { - _logger.Error(ex, "Update process failed"); - throw new CommandFailedException("Startup folder not writable by user '{0}'", ex, Environment.UserName); - } - catch (UpdateVerificationFailedException ex) - { - _logger.Error(ex, "Update process failed"); - throw new CommandFailedException("Downloaded update package is corrupt", ex); - } - catch (UpdateFailedException ex) - { - _logger.Error(ex, "Update process failed"); - throw new CommandFailedException(ex); + try + { + InstallUpdate(latestAvailable); + _logger.ProgressDebug("Restarting Radarr to apply updates"); + } + catch (UpdateFolderNotWritableException ex) + { + _logger.Error(ex, "Update process failed"); + throw new CommandFailedException("Startup folder not writable by user '{0}'", ex, Environment.UserName); + } + catch (UpdateVerificationFailedException ex) + { + _logger.Error(ex, "Update process failed"); + throw new CommandFailedException("Downloaded update package is corrupt", ex); + } + catch (UpdateFailedException ex) + { + _logger.Error(ex, "Update process failed"); + throw new CommandFailedException(ex); + } } } }