From 7a0090c7a265f53408e269ce424d9a4e5ac9583e Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 21 Feb 2022 19:47:33 -0800 Subject: [PATCH] Fixed: Schedule refresh and process monitored download tasks at high priority --- src/NzbDrone.Core/Jobs/TaskManager.cs | 2 ++ .../Commands/CommandPriorityComparer.cs | 32 +++++++++++++++++++ src/Sonarr.Api.V3/Commands/CommandModule.cs | 7 +++- 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/NzbDrone.Core/Messaging/Commands/CommandPriorityComparer.cs diff --git a/src/NzbDrone.Core/Jobs/TaskManager.cs b/src/NzbDrone.Core/Jobs/TaskManager.cs index c74c58beb..de7ab3222 100644 --- a/src/NzbDrone.Core/Jobs/TaskManager.cs +++ b/src/NzbDrone.Core/Jobs/TaskManager.cs @@ -158,6 +158,8 @@ namespace NzbDrone.Core.Jobs currentDefinition.LastExecution = DateTime.UtcNow; } + currentDefinition.Priority = defaultTask.Priority; + _cache.Set(currentDefinition.TypeName, currentDefinition); _scheduledTaskRepository.Upsert(currentDefinition); } diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandPriorityComparer.cs b/src/NzbDrone.Core/Messaging/Commands/CommandPriorityComparer.cs new file mode 100644 index 000000000..d3be33d59 --- /dev/null +++ b/src/NzbDrone.Core/Messaging/Commands/CommandPriorityComparer.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace NzbDrone.Core.Messaging.Commands +{ + public class CommandPriorityComparer: IComparer + { + public int Compare(CommandStatus x, CommandStatus y) + { + if (x == CommandStatus.Started && y != CommandStatus.Started) + { + return -1; + } + + if (x != CommandStatus.Started && y == CommandStatus.Started) + { + return 1; + } + + if (x < y) + { + return -1; + } + + if (x > y) + { + return 1; + } + + return 0; + } + } +} diff --git a/src/Sonarr.Api.V3/Commands/CommandModule.cs b/src/Sonarr.Api.V3/Commands/CommandModule.cs index a9e89e10b..fd4964296 100644 --- a/src/Sonarr.Api.V3/Commands/CommandModule.cs +++ b/src/Sonarr.Api.V3/Commands/CommandModule.cs @@ -21,6 +21,8 @@ namespace Sonarr.Api.V3.Commands private readonly Debouncer _debouncer; private readonly Dictionary _pendingUpdates; + private readonly CommandPriorityComparer _commandPriorityComparer = new CommandPriorityComparer(); + public CommandModule(IManageCommandQueue commandQueueManager, IBroadcastSignalRMessage signalRBroadcaster, IServiceFactory serviceFactory) @@ -65,7 +67,10 @@ namespace Sonarr.Api.V3.Commands private List GetStartedCommands() { - return _commandQueueManager.All().ToResource(); + return _commandQueueManager.All() + .OrderBy(c => c.Status, _commandPriorityComparer) + .ThenByDescending(c => c.Priority) + .ToResource(); } private void CancelCommand(int id)