mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-30 10:51:42 +00:00
Partial updates for command updates
This commit is contained in:
parent
97cbdfdc5c
commit
6ab629ea98
4 changed files with 17 additions and 25 deletions
|
@ -102,7 +102,7 @@ public IEnumerable<CommandModel> Queue(CancellationToken cancellationToken)
|
||||||
|
|
||||||
public CommandModel Get(int id)
|
public CommandModel Get(int id)
|
||||||
{
|
{
|
||||||
return _commandCache.Get(id.ToString(), () => FindMessage(_repo.Get(id)));
|
return _commandCache.Get(id.ToString(), () => FindCommand(_repo.Get(id)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CommandModel> GetStarted()
|
public List<CommandModel> GetStarted()
|
||||||
|
@ -124,7 +124,7 @@ public void Start(CommandModel command)
|
||||||
|
|
||||||
_logger.Trace("Marking command as started: {0}", command.Name);
|
_logger.Trace("Marking command as started: {0}", command.Name);
|
||||||
_commandCache.Set(command.Id.ToString(), command);
|
_commandCache.Set(command.Id.ToString(), command);
|
||||||
_repo.Update(command);
|
_repo.Start(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Complete(CommandModel command, string message)
|
public void Complete(CommandModel command, string message)
|
||||||
|
@ -170,7 +170,7 @@ private dynamic GetCommand(string commandName)
|
||||||
return Json.Deserialize("{}", commandType);
|
return Json.Deserialize("{}", commandType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandModel FindMessage(CommandModel command)
|
private CommandModel FindCommand(CommandModel command)
|
||||||
{
|
{
|
||||||
var cachedCommand = _commandCache.Find(command.Id.ToString());
|
var cachedCommand = _commandCache.Find(command.Id.ToString());
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ private void Update(CommandModel command, CommandStatus status, string message)
|
||||||
|
|
||||||
_logger.Trace("Updating command status");
|
_logger.Trace("Updating command status");
|
||||||
_commandCache.Set(command.Id.ToString(), command);
|
_commandCache.Set(command.Id.ToString(), command);
|
||||||
_repo.Update(command);
|
_repo.End(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CommandModel> QueuedOrStarted(string name)
|
private List<CommandModel> QueuedOrStarted(string name)
|
||||||
|
@ -206,6 +206,7 @@ public void Handle(ApplicationStartedEvent message)
|
||||||
{
|
{
|
||||||
_logger.Trace("Orphaning incomplete commands");
|
_logger.Trace("Orphaning incomplete commands");
|
||||||
_repo.OrphanStarted();
|
_repo.OrphanStarted();
|
||||||
|
Requeue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ public interface ICommandRepository : IBasicRepository<CommandModel>
|
||||||
List<CommandModel> FindQueuedOrStarted(string name);
|
List<CommandModel> FindQueuedOrStarted(string name);
|
||||||
List<CommandModel> Queued();
|
List<CommandModel> Queued();
|
||||||
List<CommandModel> Started();
|
List<CommandModel> Started();
|
||||||
|
void Start(CommandModel command);
|
||||||
|
void End(CommandModel command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CommandRepository : BasicRepository<CommandModel>, ICommandRepository
|
public class CommandRepository : BasicRepository<CommandModel>, ICommandRepository
|
||||||
|
@ -67,5 +69,15 @@ public List<CommandModel> Started()
|
||||||
{
|
{
|
||||||
return Query.Where(c => c.Status == CommandStatus.Started);
|
return Query.Where(c => c.Status == CommandStatus.Started);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Start(CommandModel command)
|
||||||
|
{
|
||||||
|
SetFields(command, c => c.StartedAt, c => c.Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void End(CommandModel command)
|
||||||
|
{
|
||||||
|
SetFields(command, c => c.EndedAt, c => c.Status, c => c.Duration);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
using NzbDrone.Core.Lifecycle;
|
|
||||||
using NzbDrone.Core.Messaging.Events;
|
|
||||||
|
|
||||||
namespace NzbDrone.Core.Messaging.Commands
|
|
||||||
{
|
|
||||||
public class RequeueQueuedCommands : IHandle<ApplicationStartedEvent>
|
|
||||||
{
|
|
||||||
private readonly IManageCommandQueue _commandQueueManager;
|
|
||||||
|
|
||||||
public RequeueQueuedCommands(IManageCommandQueue commandQueueManager)
|
|
||||||
{
|
|
||||||
_commandQueueManager = commandQueueManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Handle(ApplicationStartedEvent message)
|
|
||||||
{
|
|
||||||
_commandQueueManager.Requeue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -621,7 +621,6 @@
|
||||||
<Compile Include="Messaging\Commands\CommandQueueManager.cs" />
|
<Compile Include="Messaging\Commands\CommandQueueManager.cs" />
|
||||||
<Compile Include="Messaging\Commands\CommandTrigger.cs" />
|
<Compile Include="Messaging\Commands\CommandTrigger.cs" />
|
||||||
<Compile Include="Messaging\Commands\IExecute.cs" />
|
<Compile Include="Messaging\Commands\IExecute.cs" />
|
||||||
<Compile Include="Messaging\Commands\RequeueQueuedCommands.cs" />
|
|
||||||
<Compile Include="Messaging\Commands\TestCommand.cs" />
|
<Compile Include="Messaging\Commands\TestCommand.cs" />
|
||||||
<Compile Include="Messaging\Commands\TestCommandExecutor.cs" />
|
<Compile Include="Messaging\Commands\TestCommandExecutor.cs" />
|
||||||
<Compile Include="Messaging\Events\CommandExecutedEvent.cs" />
|
<Compile Include="Messaging\Events\CommandExecutedEvent.cs" />
|
||||||
|
|
Loading…
Reference in a new issue