mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
Command queue
New: Adding multiple series will queue them instead of running all at once New: Slower scheduled tasks won't be block others from running
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
@@ -15,15 +16,15 @@ namespace NzbDrone.Core.Jobs
|
||||
IHandle<ApplicationShutdownRequested>
|
||||
{
|
||||
private readonly ITaskManager _taskManager;
|
||||
private readonly ICommandExecutor _commandExecutor;
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
private readonly Logger _logger;
|
||||
private static readonly Timer Timer = new Timer();
|
||||
private static CancellationTokenSource _cancellationTokenSource;
|
||||
|
||||
public Scheduler(ITaskManager taskManager, ICommandExecutor commandExecutor, Logger logger)
|
||||
public Scheduler(ITaskManager taskManager, IManageCommandQueue commandQueueManager, Logger logger)
|
||||
{
|
||||
_taskManager = taskManager;
|
||||
_commandExecutor = commandExecutor;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
@@ -33,24 +34,16 @@ namespace NzbDrone.Core.Jobs
|
||||
{
|
||||
Timer.Enabled = false;
|
||||
|
||||
var tasks = _taskManager.GetPending();
|
||||
var tasks = _taskManager.GetPending().ToList();
|
||||
|
||||
_logger.Trace("Pending Tasks: {0}", tasks.Count);
|
||||
|
||||
foreach (var task in tasks)
|
||||
{
|
||||
_cancellationTokenSource.Token.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
_commandExecutor.PublishCommand(task.TypeName, task.LastExecution);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.ErrorException("Error occurred while executing task " + task.TypeName, e);
|
||||
}
|
||||
_commandQueueManager.Push(task.TypeName, task.LastExecution, CommandPriority.Low, CommandTrigger.Scheduled);
|
||||
}
|
||||
}
|
||||
|
||||
finally
|
||||
{
|
||||
if (!_cancellationTokenSource.IsCancellationRequested)
|
||||
|
Reference in New Issue
Block a user