From 1f14276770329d017b8b7396e003a875c7d4a755 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 7 Aug 2022 12:26:37 -0700 Subject: [PATCH] Don't block task queue for queued update task when there are longer running tasks executing --- .../Download/ProcessMonitoredDownloadsCommand.cs | 2 ++ src/NzbDrone.Core/Indexers/RssSyncCommand.cs | 4 +++- src/NzbDrone.Core/Messaging/Commands/Command.cs | 1 + .../Messaging/Commands/CommandQueue.cs | 13 ++++++++++++- .../Tv/Commands/RefreshSeriesCommand.cs | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/Download/ProcessMonitoredDownloadsCommand.cs b/src/NzbDrone.Core/Download/ProcessMonitoredDownloadsCommand.cs index c3c934031..4b39f1347 100644 --- a/src/NzbDrone.Core/Download/ProcessMonitoredDownloadsCommand.cs +++ b/src/NzbDrone.Core/Download/ProcessMonitoredDownloadsCommand.cs @@ -5,5 +5,7 @@ namespace NzbDrone.Core.Download public class ProcessMonitoredDownloadsCommand : Command { public override bool RequiresDiskAccess => true; + + public override bool IsLongRunning => true; } } diff --git a/src/NzbDrone.Core/Indexers/RssSyncCommand.cs b/src/NzbDrone.Core/Indexers/RssSyncCommand.cs index 47b9cca67..4722b32f2 100644 --- a/src/NzbDrone.Core/Indexers/RssSyncCommand.cs +++ b/src/NzbDrone.Core/Indexers/RssSyncCommand.cs @@ -1,9 +1,11 @@ -using NzbDrone.Core.Messaging.Commands; +using NzbDrone.Core.Messaging.Commands; namespace NzbDrone.Core.Indexers { public class RssSyncCommand : Command { public override bool SendUpdatesToClient => true; + + public override bool IsLongRunning => true; } } diff --git a/src/NzbDrone.Core/Messaging/Commands/Command.cs b/src/NzbDrone.Core/Messaging/Commands/Command.cs index 03f3369ba..39b787f41 100644 --- a/src/NzbDrone.Core/Messaging/Commands/Command.cs +++ b/src/NzbDrone.Core/Messaging/Commands/Command.cs @@ -26,6 +26,7 @@ namespace NzbDrone.Core.Messaging.Commands public virtual string CompletionMessage => "Completed"; public virtual bool RequiresDiskAccess => false; public virtual bool IsExclusive => false; + public virtual bool IsLongRunning => false; public string Name { get; private set; } public DateTime? LastExecutionTime { get; set; } diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandQueue.cs b/src/NzbDrone.Core/Messaging/Commands/CommandQueue.cs index b77e7fecb..c44d58d7a 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandQueue.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandQueue.cs @@ -164,13 +164,24 @@ namespace NzbDrone.Core.Messaging.Commands { // If an executing command requires disk access don't return a command that // requires disk access. A lower priority or later queued task could be returned - // instead, but that will allow other tasks to execute whiule waiting for disk access. + // instead, but that will allow other tasks to execute while waiting for disk access. if (startedCommands.Any(x => x.Body.RequiresDiskAccess)) { return c.Status == CommandStatus.Queued && !c.Body.RequiresDiskAccess; } + // If an executing command is long running then skip any exclusive commands until + // they complete. A lower priority or later queued task could be returned + // instead, but that will allow other tasks to execute while waiting for exclusive + // execution. + + if (startedCommands.Any(x => x.Body.IsLongRunning)) + { + return c.Status == CommandStatus.Queued && + !c.Body.IsExclusive; + } + return c.Status == CommandStatus.Queued; }) .OrderByDescending(c => c.Priority) diff --git a/src/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs b/src/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs index 98657351e..5cedb151e 100644 --- a/src/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs +++ b/src/NzbDrone.Core/Tv/Commands/RefreshSeriesCommand.cs @@ -20,5 +20,7 @@ namespace NzbDrone.Core.Tv.Commands public override bool SendUpdatesToClient => true; public override bool UpdateScheduledTask => !SeriesId.HasValue; + + public override bool IsLongRunning => true; } }