mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-31 03:11:51 +00:00
Use cache to check for running or started commands
This commit is contained in:
parent
210524b51a
commit
755a42ea45
2 changed files with 15 additions and 4 deletions
|
@ -51,6 +51,10 @@ private void ExecuteCommands()
|
||||||
_logger.ErrorException(ex.Message, ex);
|
_logger.ErrorException(ex.Message, ex);
|
||||||
Thread.ResetAbort();
|
Thread.ResetAbort();
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error(ex.Message, ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ExecuteCommand<TCommand>(TCommand command, CommandModel commandModel) where TCommand : Command
|
private void ExecuteCommand<TCommand>(TCommand command, CommandModel commandModel) where TCommand : Command
|
||||||
|
|
|
@ -57,7 +57,7 @@ public CommandModel Push<TCommand>(TCommand command, CommandPriority priority =
|
||||||
_logger.Trace("Publishing {0}", command.Name);
|
_logger.Trace("Publishing {0}", command.Name);
|
||||||
_logger.Trace("Checking if command is queued or started: {0}", command.Name);
|
_logger.Trace("Checking if command is queued or started: {0}", command.Name);
|
||||||
|
|
||||||
var existingCommands = _repo.FindQueuedOrStarted(command.Name);
|
var existingCommands = QueuedOrStarted(command.Name);
|
||||||
var existing = existingCommands.SingleOrDefault(c => CommandEqualityComparer.Instance.Equals(c.Body, command));
|
var existing = existingCommands.SingleOrDefault(c => CommandEqualityComparer.Instance.Equals(c.Body, command));
|
||||||
|
|
||||||
if (existing != null)
|
if (existing != null)
|
||||||
|
@ -123,8 +123,8 @@ public void Start(CommandModel command)
|
||||||
command.Status = CommandStatus.Started;
|
command.Status = CommandStatus.Started;
|
||||||
|
|
||||||
_logger.Trace("Marking command as started: {0}", command.Name);
|
_logger.Trace("Marking command as started: {0}", command.Name);
|
||||||
_repo.Update(command);
|
|
||||||
_commandCache.Set(command.Id.ToString(), command);
|
_commandCache.Set(command.Id.ToString(), command);
|
||||||
|
_repo.Update(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Complete(CommandModel command, string message)
|
public void Complete(CommandModel command, string message)
|
||||||
|
@ -191,8 +191,15 @@ private void Update(CommandModel command, CommandStatus status, string message)
|
||||||
command.Status = status;
|
command.Status = status;
|
||||||
|
|
||||||
_logger.Trace("Updating command status");
|
_logger.Trace("Updating command status");
|
||||||
_repo.Update(command);
|
|
||||||
_commandCache.Set(command.Id.ToString(), command);
|
_commandCache.Set(command.Id.ToString(), command);
|
||||||
|
_repo.Update(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<CommandModel> QueuedOrStarted(string name)
|
||||||
|
{
|
||||||
|
return _commandCache.Values.Where(q => q.Name == name &&
|
||||||
|
(q.Status == CommandStatus.Queued ||
|
||||||
|
q.Status == CommandStatus.Started)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Handle(ApplicationStartedEvent message)
|
public void Handle(ApplicationStartedEvent message)
|
||||||
|
|
Loading…
Reference in a new issue