From 257d38de669a780471a41c7f65e36d64955e4ac0 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 17 Oct 2024 04:46:15 +0300 Subject: [PATCH] Inherit trigger from pushed command models (cherry picked from commit 0bc4903954b955fce0c368ef7fd2a6f3761d6a93) --- .../Messaging/Commands/CommandQueueManager.cs | 7 ++++--- src/Prowlarr.Api.V1/Commands/CommandController.cs | 3 +-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs b/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs index 12ce4cb06..6ad659294 100644 --- a/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs +++ b/src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs @@ -105,6 +105,8 @@ namespace NzbDrone.Core.Messaging.Commands _logger.Trace("Publishing {0}", command.Name); _logger.Trace("Checking if command is queued or started: {0}", command.Name); + command.Trigger = trigger; + lock (_commandQueue) { var existingCommands = QueuedOrStarted(command.Name); @@ -141,7 +143,6 @@ namespace NzbDrone.Core.Messaging.Commands var command = GetCommand(commandName); command.LastExecutionTime = lastExecutionTime; command.LastStartTime = lastStartTime; - command.Trigger = trigger; return Push(command, priority, trigger); } @@ -232,13 +233,13 @@ namespace NzbDrone.Core.Messaging.Commands _repo.Trim(); } - private dynamic GetCommand(string commandName) + private Command GetCommand(string commandName) { commandName = commandName.Split('.').Last(); var commands = _knownTypes.GetImplementations(typeof(Command)); var commandType = commands.Single(c => c.Name.Equals(commandName, StringComparison.InvariantCultureIgnoreCase)); - return Json.Deserialize("{}", commandType); + return Json.Deserialize("{}", commandType) as Command; } private void Update(CommandModel command, CommandStatus status, string message) diff --git a/src/Prowlarr.Api.V1/Commands/CommandController.cs b/src/Prowlarr.Api.V1/Commands/CommandController.cs index f74192f55..714685b22 100644 --- a/src/Prowlarr.Api.V1/Commands/CommandController.cs +++ b/src/Prowlarr.Api.V1/Commands/CommandController.cs @@ -61,9 +61,8 @@ namespace Prowlarr.Api.V1.Commands using var reader = new StreamReader(Request.Body); var body = reader.ReadToEnd(); - dynamic command = STJson.Deserialize(body, commandType); + var command = STJson.Deserialize(body, commandType) as Command; - command.Trigger = CommandTrigger.Manual; command.SuppressMessages = !command.SendUpdatesToClient; command.SendUpdatesToClient = true; command.ClientUserAgent = Request.Headers["User-Agent"];