mirror of
https://github.com/lidarr/Lidarr
synced 2025-02-25 15:22:42 +00:00
New: Cancel tasks in command queue
This commit is contained in:
parent
61387b3d44
commit
9d2fbddc7d
5 changed files with 33 additions and 3 deletions
|
@ -176,6 +176,7 @@ export const actionHandlers = handleThunks({
|
|||
}
|
||||
});
|
||||
|
||||
dispatch(updateItem({ section: 'commands', ...payload }));
|
||||
scheduleRemoveCommand(payload, dispatch);
|
||||
showCommandMessage(payload, dispatch);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ function createCommandExecutingSelector(name, contraints = {}) {
|
|||
return createSelector(
|
||||
createCommandsSelector(),
|
||||
(commands) => {
|
||||
return isCommandExecuting(findCommand(commands, { name, ...contraints }));
|
||||
const command = findCommand(commands, { name, ...contraints });
|
||||
return isCommandExecuting(command);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -68,8 +68,7 @@ private List<CommandResource> GetStartedCommands()
|
|||
|
||||
private void CancelCommand(int id)
|
||||
{
|
||||
// TODO: Cancel the existing command
|
||||
// Executing tasks should preferably exit gracefully
|
||||
_commandQueueManager.Cancel(id);
|
||||
}
|
||||
|
||||
public void Handle(CommandUpdatedEvent message)
|
||||
|
|
|
@ -71,6 +71,24 @@ public void RemoveMany(IEnumerable<CommandModel> commands)
|
|||
}
|
||||
}
|
||||
|
||||
public bool RemoveIfQueued(int id)
|
||||
{
|
||||
var rval = false;
|
||||
|
||||
lock (_mutex)
|
||||
{
|
||||
var command = _items.FirstOrDefault(q => q.Id == id);
|
||||
|
||||
if (command?.Status == CommandStatus.Queued)
|
||||
{
|
||||
_items.Remove(command);
|
||||
rval = true;
|
||||
}
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
public List<CommandModel> QueuedOrStarted()
|
||||
{
|
||||
return All().Where(q => q.Status == CommandStatus.Queued || q.Status == CommandStatus.Started)
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Exceptions;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Messaging.Commands
|
||||
|
@ -25,6 +27,7 @@ public interface IManageCommandQueue
|
|||
void Complete(CommandModel command, string message);
|
||||
void Fail(CommandModel command, string message, Exception e);
|
||||
void Requeue();
|
||||
void Cancel(int id);
|
||||
void CleanCommands();
|
||||
}
|
||||
|
||||
|
@ -193,6 +196,14 @@ public void Requeue()
|
|||
}
|
||||
}
|
||||
|
||||
public void Cancel(int id)
|
||||
{
|
||||
if (!_commandQueue.RemoveIfQueued(id))
|
||||
{
|
||||
throw new NzbDroneClientException(HttpStatusCode.Conflict, "Unable to cancel task");
|
||||
}
|
||||
}
|
||||
|
||||
public void CleanCommands()
|
||||
{
|
||||
_logger.Trace("Cleaning up old commands");
|
||||
|
|
Loading…
Reference in a new issue