diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs b/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs index bb91685f6..7f44827e3 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs @@ -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 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 QueuedOrStarted(string name) @@ -206,6 +206,7 @@ namespace NzbDrone.Core.Messaging.Commands { _logger.Trace("Orphaning incomplete commands"); _repo.OrphanStarted(); + Requeue(); } } } diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandRepository.cs b/src/NzbDrone.Core/Messaging/Commands/CommandRepository.cs index 27d167315..6a30213dc 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandRepository.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandRepository.cs @@ -14,6 +14,8 @@ namespace NzbDrone.Core.Messaging.Commands List FindQueuedOrStarted(string name); List Queued(); List Started(); + void Start(CommandModel command); + void End(CommandModel command); } public class CommandRepository : BasicRepository, 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); + } } } diff --git a/src/NzbDrone.Core/Messaging/Commands/RequeueQueuedCommands.cs b/src/NzbDrone.Core/Messaging/Commands/RequeueQueuedCommands.cs deleted file mode 100644 index 43f75c891..000000000 --- a/src/NzbDrone.Core/Messaging/Commands/RequeueQueuedCommands.cs +++ /dev/null @@ -1,20 +0,0 @@ -using NzbDrone.Core.Lifecycle; -using NzbDrone.Core.Messaging.Events; - -namespace NzbDrone.Core.Messaging.Commands -{ - public class RequeueQueuedCommands : IHandle - { - private readonly IManageCommandQueue _commandQueueManager; - - public RequeueQueuedCommands(IManageCommandQueue commandQueueManager) - { - _commandQueueManager = commandQueueManager; - } - - public void Handle(ApplicationStartedEvent message) - { - _commandQueueManager.Requeue(); - } - } -} diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 1cf927c50..eb0c1f52d 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -621,7 +621,6 @@ -