Fixed timing issue allowing multiple instances of the same command to be queued

pull/3735/head
Taloth Saldono 4 years ago
parent c8d2fcb223
commit 013c46d266

@ -96,32 +96,35 @@ namespace NzbDrone.Core.Messaging.Commands
_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 = QueuedOrStarted(command.Name); lock (_commandQueue)
var existing = existingCommands.SingleOrDefault(c => CommandEqualityComparer.Instance.Equals(c.Body, command));
if (existing != null)
{ {
_logger.Trace("Command is already in progress: {0}", command.Name); var existingCommands = QueuedOrStarted(command.Name);
var existing = existingCommands.FirstOrDefault(c => CommandEqualityComparer.Instance.Equals(c.Body, command));
return existing; if (existing != null)
} {
_logger.Trace("Command is already in progress: {0}", command.Name);
var commandModel = new CommandModel return existing;
{ }
Name = command.Name,
Body = command, var commandModel = new CommandModel
QueuedAt = DateTime.UtcNow, {
Trigger = trigger, Name = command.Name,
Priority = priority, Body = command,
Status = CommandStatus.Queued QueuedAt = DateTime.UtcNow,
}; Trigger = trigger,
Priority = priority,
Status = CommandStatus.Queued
};
_logger.Trace("Inserting new command: {0}", commandModel.Name); _logger.Trace("Inserting new command: {0}", commandModel.Name);
_repo.Insert(commandModel); _repo.Insert(commandModel);
_commandQueue.Add(commandModel); _commandQueue.Add(commandModel);
return commandModel; return commandModel;
}
} }
public CommandModel Push(string commandName, DateTime? lastExecutionTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified) public CommandModel Push(string commandName, DateTime? lastExecutionTime, CommandPriority priority = CommandPriority.Normal, CommandTrigger trigger = CommandTrigger.Unspecified)

Loading…
Cancel
Save