Don't block task queue for queued update task when long running tasks queued

Fixes #2935

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/3241/head
Qstick 2 years ago
parent 5a8082de2d
commit 93cce9a02e

@ -3,6 +3,7 @@ using FluentAssertions;
using NUnit.Framework;
using NzbDrone.Core.Download;
using NzbDrone.Core.ImportLists;
using NzbDrone.Core.Indexers;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Music.Commands;
using NzbDrone.Core.Test.Framework;
@ -25,6 +26,18 @@ namespace NzbDrone.Core.Test.Messaging.Commands
Subject.Add(commandModel);
}
private void GivenLongRunningCommand()
{
var commandModel = Builder<CommandModel>
.CreateNew()
.With(c => c.Name = "RssSync")
.With(c => c.Body = new RssSyncCommand())
.With(c => c.Status = CommandStatus.Started)
.Build();
Subject.Add(commandModel);
}
private void GivenStartedTypeExclusiveCommand()
{
var commandModel = Builder<CommandModel>
@ -85,6 +98,24 @@ namespace NzbDrone.Core.Test.Messaging.Commands
command.Should().BeNull();
}
[Test]
public void should_not_return_exclusive_command_if_long_running_command_running()
{
GivenLongRunningCommand();
var newCommandModel = Builder<CommandModel>
.CreateNew()
.With(c => c.Name = "ApplicationUpdate")
.With(c => c.Body = new ApplicationUpdateCommand())
.Build();
Subject.Add(newCommandModel);
Subject.TryGet(out var command);
command.Should().BeNull();
}
[Test]
public void should_not_return_type_exclusive_command_if_another_and_disk_access_command_running()
{

@ -5,5 +5,7 @@ namespace NzbDrone.Core.Download
public class ProcessMonitoredDownloadsCommand : Command
{
public override bool RequiresDiskAccess => true;
public override bool IsLongRunning => true;
}
}

@ -5,5 +5,7 @@ namespace NzbDrone.Core.Indexers
public class RssSyncCommand : Command
{
public override bool SendUpdatesToClient => true;
public override bool IsLongRunning => true;
}
}

@ -26,8 +26,8 @@ namespace NzbDrone.Core.Messaging.Commands
public virtual string CompletionMessage => "Completed";
public virtual bool RequiresDiskAccess => false;
public virtual bool IsExclusive => false;
public virtual bool IsTypeExclusive => false;
public virtual bool IsLongRunning => false;
public string Name { get; private set; }
public DateTime? LastExecutionTime { get; set; }

@ -176,6 +176,11 @@ namespace NzbDrone.Core.Messaging.Commands
queuedCommands = queuedCommands.Where(c => !exclusiveTypes.Any(x => x == c.Body.Name));
}
if (startedCommands.Any(x => x.Body.IsLongRunning))
{
queuedCommands = queuedCommands.Where(c => c.Status == CommandStatus.Queued && !c.Body.IsExclusive);
}
var localItem = queuedCommands.OrderByDescending(c => c.Priority)
.ThenBy(c => c.QueuedAt)
.FirstOrDefault();

Loading…
Cancel
Save