diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index 577ff8fe1..8aebe80ff 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -106,7 +106,16 @@ private async void OnIsarStatus(object? sender, MqttReceivedArgs mqttArgs) _logger.LogInformation("OnIsarStatus: Robot {robotName} has status {robotStatus} and current area {areaName}", updatedRobot.Name, updatedRobot.Status, updatedRobot.CurrentArea?.Name); - if (isarStatus.Status == RobotStatus.Available) MissionScheduling.TriggerRobotAvailable(new RobotAvailableEventArgs(robot.Id)); + if (isarStatus.Status == RobotStatus.Available) + { + try { await RobotService.UpdateCurrentMissionId(robot.Id, null); } + catch (RobotNotFoundException) + { + _logger.LogError("Robot {robotName} not found when updating current mission id to null", robot.Name); + return; + } + MissionScheduling.TriggerRobotAvailable(new RobotAvailableEventArgs(robot.Id)); + } else if (isarStatus.Status == RobotStatus.Offline) { await RobotService.UpdateCurrentArea(robot.Id, null); @@ -333,16 +342,6 @@ private async void OnIsarMissionUpdate(object? sender, MqttReceivedArgs mqttArgs } } - try - { - await RobotService.UpdateCurrentMissionId(robot.Id, null); - } - catch (RobotNotFoundException) - { - _logger.LogError("Robot {robotName} not found when updating current mission id to null", robot.Name); - return; - } - _logger.LogInformation("Robot '{Id}' ('{Name}') - completed mission run {MissionRunId}", robot.IsarId, robot.Name, updatedFlotillaMissionRun.Id); if (updatedFlotillaMissionRun.IsLocalizationMission() && (updatedFlotillaMissionRun.Status == MissionStatus.Successful || updatedFlotillaMissionRun.Status == MissionStatus.PartiallySuccessful))