Skip to content

Commit

Permalink
Inherit trigger from pushed command models
Browse files Browse the repository at this point in the history
(cherry picked from commit 0bc4903954b955fce0c368ef7fd2a6f3761d6a93)

Closes Lidarr#5181
  • Loading branch information
mynameisbogdan committed Oct 27, 2024
1 parent a843a46 commit 8623b44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/Lidarr.Api.V1/Artist/ArtistController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ public ActionResult<ArtistResource> UpdateArtist(ArtistResource artistResource,
ArtistId = artist.Id,
SourcePath = sourcePath,
DestinationPath = destinationPath,
MoveFiles = moveFiles,
Trigger = CommandTrigger.Manual
});
MoveFiles = moveFiles
}, trigger: CommandTrigger.Manual);

var model = artistResource.ToModel(artist);

Expand Down
3 changes: 1 addition & 2 deletions src/Lidarr.Api.V1/Commands/CommandController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ public ActionResult<CommandResource> StartCommand(CommandResource commandResourc
? CommandPriority.High
: CommandPriority.Normal;

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["UserAgent"];
Expand Down
7 changes: 4 additions & 3 deletions src/NzbDrone.Core/Messaging/Commands/CommandQueueManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ public CommandModel Push<TCommand>(TCommand command, CommandPriority priority =
_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);
Expand Down Expand Up @@ -142,7 +144,6 @@ public CommandModel Push(string commandName, DateTime? lastExecutionTime, DateTi
var command = GetCommand(commandName);
command.LastExecutionTime = lastExecutionTime;
command.LastStartTime = lastStartTime;
command.Trigger = trigger;

return Push(command, priority, trigger);
}
Expand Down Expand Up @@ -244,13 +245,13 @@ public void CleanCommands()
_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)
Expand Down

0 comments on commit 8623b44

Please sign in to comment.