1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2025-02-23 22:40:54 +00:00

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>
This commit is contained in:
Qstick 2023-01-14 17:52:11 -06:00
parent 5a8082de2d
commit 93cce9a02e
5 changed files with 45 additions and 5 deletions

View file

@ -3,6 +3,7 @@
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 @@ private void GivenStartedDiskCommand()
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 @@ public void should_not_return_type_exclusive_command_if_another_running()
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()
{

View file

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

View file

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

View file

@ -26,8 +26,8 @@ public virtual bool SendUpdatesToClient
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; }

View file

@ -98,7 +98,7 @@ public bool RemoveIfQueued(int id)
public List<CommandModel> QueuedOrStarted()
{
return All().Where(q => q.Status == CommandStatus.Queued || q.Status == CommandStatus.Started)
.ToList();
.ToList();
}
public IEnumerable<CommandModel> GetConsumingEnumerable()
@ -158,7 +158,7 @@ public bool TryGet(out CommandModel item)
else
{
var startedCommands = _items.Where(c => c.Status == CommandStatus.Started)
.ToList();
.ToList();
var exclusiveTypes = startedCommands.Where(x => x.Body.IsTypeExclusive)
.Select(x => x.Body.Name)
@ -176,9 +176,14 @@ public bool TryGet(out CommandModel item)
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();
.ThenBy(c => c.QueuedAt)
.FirstOrDefault();
// Nothing queued that meets the requirements
if (localItem == null)