mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
New: Queued Task/Command List View
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
9a1660da51
commit
60bb0ac063
31 changed files with 897 additions and 287 deletions
|
@ -32,6 +32,7 @@ namespace Lidarr.Api.V1.Commands
|
|||
GetResourceById = GetCommand;
|
||||
CreateResource = StartCommand;
|
||||
GetResourceAll = GetStartedCommands;
|
||||
DeleteResource = CancelCommand;
|
||||
|
||||
PostValidator.RuleFor(c => c.Name).NotBlank();
|
||||
|
||||
|
@ -62,7 +63,13 @@ namespace Lidarr.Api.V1.Commands
|
|||
|
||||
private List<CommandResource> GetStartedCommands()
|
||||
{
|
||||
return _commandQueueManager.GetStarted().ToResource();
|
||||
return _commandQueueManager.All().ToResource();
|
||||
}
|
||||
|
||||
private void CancelCommand(int id)
|
||||
{
|
||||
// TODO: Cancel the existing command
|
||||
// Executing tasks should preferably exit gracefully
|
||||
}
|
||||
|
||||
public void Handle(CommandUpdatedEvent message)
|
||||
|
@ -75,6 +82,13 @@ namespace Lidarr.Api.V1.Commands
|
|||
}
|
||||
_debouncer.Execute();
|
||||
}
|
||||
|
||||
if (message.Command.Name == typeof(MessagingCleanupCommand).Name.Replace("Command", "") &&
|
||||
message.Command.Status == CommandStatus.Completed)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Sync);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SendUpdates()
|
||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
using Lidarr.Http.REST;
|
||||
|
||||
|
@ -10,6 +11,7 @@ namespace Lidarr.Api.V1.Commands
|
|||
public class CommandResource : RestResource
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string CommandName { get; set; }
|
||||
public string Message { get; set; }
|
||||
public Command Body { get; set; }
|
||||
public CommandPriority Priority { get; set; }
|
||||
|
@ -75,6 +77,7 @@ namespace Lidarr.Api.V1.Commands
|
|||
Id = model.Id,
|
||||
|
||||
Name = model.Name,
|
||||
CommandName = model.Name.SplitCamelCase(),
|
||||
Message = model.Message,
|
||||
Body = model.Body,
|
||||
Priority = model.Priority,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Datastore.Events;
|
||||
using NzbDrone.Core.Jobs;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
@ -13,8 +14,6 @@ namespace Lidarr.Api.V1.System.Tasks
|
|||
{
|
||||
private readonly ITaskManager _taskManager;
|
||||
|
||||
private static readonly Regex NameRegex = new Regex("(?<!^)[A-Z]", RegexOptions.Compiled);
|
||||
|
||||
public TaskModule(ITaskManager taskManager, IBroadcastSignalRMessage broadcastSignalRMessage)
|
||||
: base(broadcastSignalRMessage, "system/task")
|
||||
{
|
||||
|
@ -51,7 +50,7 @@ namespace Lidarr.Api.V1.System.Tasks
|
|||
return new TaskResource
|
||||
{
|
||||
Id = scheduledTask.Id,
|
||||
Name = NameRegex.Replace(taskName, match => " " + match.Value),
|
||||
Name = taskName.SplitCamelCase(),
|
||||
TaskName = taskName,
|
||||
Interval = scheduledTask.Interval,
|
||||
LastExecution = scheduledTask.LastExecution,
|
||||
|
|
|
@ -46,20 +46,22 @@ namespace Lidarr.Http
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected void BroadcastResourceChange(ModelAction action, TResource resource)
|
||||
{
|
||||
var signalRMessage = new SignalRMessage
|
||||
if (GetType().Namespace.Contains("V1"))
|
||||
{
|
||||
Name = Resource,
|
||||
Body = new ResourceChangeMessage<TResource>(resource, action),
|
||||
Action = action
|
||||
};
|
||||
var signalRMessage = new SignalRMessage
|
||||
{
|
||||
Name = Resource,
|
||||
Body = new ResourceChangeMessage<TResource>(resource, action),
|
||||
Action = action
|
||||
};
|
||||
|
||||
_signalRBroadcaster.BroadcastMessage(signalRMessage);
|
||||
_signalRBroadcaster.BroadcastMessage(signalRMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void BroadcastResourceChange(ModelAction action)
|
||||
{
|
||||
if (GetType().Namespace.Contains("V1"))
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace NzbDrone.Common.Extensions
|
|||
{
|
||||
public static class StringExtensions
|
||||
{
|
||||
private static readonly Regex CamelCaseRegex = new Regex("(?<!^)[A-Z]", RegexOptions.Compiled);
|
||||
|
||||
public static string NullSafe(this string target)
|
||||
{
|
||||
return ((object)target).NullSafe().ToString();
|
||||
|
@ -133,5 +135,11 @@ namespace NzbDrone.Common.Extensions
|
|||
|
||||
return Encoding.ASCII.GetString(new [] { byteResult });
|
||||
}
|
||||
|
||||
public static string SplitCamelCase(this string input)
|
||||
{
|
||||
return CamelCaseRegex.Replace(input, match => " " + match.Value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,7 +151,7 @@ namespace NzbDrone.Core.Messaging.Commands
|
|||
// A command ready to execute
|
||||
else
|
||||
{
|
||||
localItem.StartedAt = DateTime.Now;
|
||||
localItem.StartedAt = DateTime.UtcNow;
|
||||
localItem.Status = CommandStatus.Started;
|
||||
|
||||
item = localItem;
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace NzbDrone.Core.Messaging.Commands
|
|||
CommandModel Push<TCommand>(TCommand command, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified) where TCommand : Command;
|
||||
CommandModel Push(string commandName, DateTime? lastExecutionTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified);
|
||||
IEnumerable<CommandModel> Queue(CancellationToken cancellationToken);
|
||||
List<CommandModel> All();
|
||||
CommandModel Get(int id);
|
||||
List<CommandModel> GetStarted();
|
||||
void SetMessage(CommandModel command, string message);
|
||||
|
@ -136,6 +137,12 @@ namespace NzbDrone.Core.Messaging.Commands
|
|||
return _commandQueue.GetConsumingEnumerable(cancellationToken);
|
||||
}
|
||||
|
||||
public List<CommandModel> All()
|
||||
{
|
||||
_logger.Trace("Getting all commands");
|
||||
return _commandQueue.All();
|
||||
}
|
||||
|
||||
public CommandModel Get(int id)
|
||||
{
|
||||
var command = _commandQueue.Find(id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue