Partial updates for command updates

pull/3113/head
Mark McDowall 10 years ago
parent 97cbdfdc5c
commit 6ab629ea98

@ -102,7 +102,7 @@ namespace NzbDrone.Core.Messaging.Commands
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()
@ -124,7 +124,7 @@ namespace NzbDrone.Core.Messaging.Commands
_logger.Trace("Marking command as started: {0}", command.Name);
_commandCache.Set(command.Id.ToString(), command);
_repo.Update(command);
_repo.Start(command);
}
public void Complete(CommandModel command, string message)
@ -170,7 +170,7 @@ namespace NzbDrone.Core.Messaging.Commands
return Json.Deserialize("{}", commandType);
}
private CommandModel FindMessage(CommandModel command)
private CommandModel FindCommand(CommandModel command)
{
var cachedCommand = _commandCache.Find(command.Id.ToString());
@ -192,7 +192,7 @@ namespace NzbDrone.Core.Messaging.Commands
_logger.Trace("Updating command status");
_commandCache.Set(command.Id.ToString(), command);
_repo.Update(command);
_repo.End(command);
}
private List<CommandModel> QueuedOrStarted(string name)
@ -206,6 +206,7 @@ namespace NzbDrone.Core.Messaging.Commands
{
_logger.Trace("Orphaning incomplete commands");
_repo.OrphanStarted();
Requeue();
}
}
}

@ -14,6 +14,8 @@ namespace NzbDrone.Core.Messaging.Commands
List<CommandModel> FindQueuedOrStarted(string name);
List<CommandModel> Queued();
List<CommandModel> Started();
void Start(CommandModel command);
void End(CommandModel command);
}
public class CommandRepository : BasicRepository<CommandModel>, ICommandRepository
@ -67,5 +69,15 @@ namespace NzbDrone.Core.Messaging.Commands
{
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\CommandTrigger.cs" />
<Compile Include="Messaging\Commands\IExecute.cs" />
<Compile Include="Messaging\Commands\RequeueQueuedCommands.cs" />
<Compile Include="Messaging\Commands\TestCommand.cs" />
<Compile Include="Messaging\Commands\TestCommandExecutor.cs" />
<Compile Include="Messaging\Events\CommandExecutedEvent.cs" />

Loading…
Cancel
Save