Fixed: Schedule refresh and process monitored download tasks at high priority

This commit is contained in:
Mark McDowall 2022-02-21 19:47:33 -08:00
parent 66be23a7c4
commit 7a0090c7a2
3 changed files with 40 additions and 1 deletions

View File

@ -158,6 +158,8 @@ namespace NzbDrone.Core.Jobs
currentDefinition.LastExecution = DateTime.UtcNow; currentDefinition.LastExecution = DateTime.UtcNow;
} }
currentDefinition.Priority = defaultTask.Priority;
_cache.Set(currentDefinition.TypeName, currentDefinition); _cache.Set(currentDefinition.TypeName, currentDefinition);
_scheduledTaskRepository.Upsert(currentDefinition); _scheduledTaskRepository.Upsert(currentDefinition);
} }

View File

@ -0,0 +1,32 @@
using System.Collections.Generic;
namespace NzbDrone.Core.Messaging.Commands
{
public class CommandPriorityComparer: IComparer<CommandStatus>
{
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;
}
}
}

View File

@ -21,6 +21,8 @@ namespace Sonarr.Api.V3.Commands
private readonly Debouncer _debouncer; private readonly Debouncer _debouncer;
private readonly Dictionary<int, CommandResource> _pendingUpdates; private readonly Dictionary<int, CommandResource> _pendingUpdates;
private readonly CommandPriorityComparer _commandPriorityComparer = new CommandPriorityComparer();
public CommandModule(IManageCommandQueue commandQueueManager, public CommandModule(IManageCommandQueue commandQueueManager,
IBroadcastSignalRMessage signalRBroadcaster, IBroadcastSignalRMessage signalRBroadcaster,
IServiceFactory serviceFactory) IServiceFactory serviceFactory)
@ -65,7 +67,10 @@ namespace Sonarr.Api.V3.Commands
private List<CommandResource> GetStartedCommands() private List<CommandResource> GetStartedCommands()
{ {
return _commandQueueManager.All().ToResource(); return _commandQueueManager.All()
.OrderBy(c => c.Status, _commandPriorityComparer)
.ThenByDescending(c => c.Priority)
.ToResource();
} }
private void CancelCommand(int id) private void CancelCommand(int id)