diff --git a/backend/api/EventHandlers/MqttEventHandler.cs b/backend/api/EventHandlers/MqttEventHandler.cs index 043737846..dd95c0172 100644 --- a/backend/api/EventHandlers/MqttEventHandler.cs +++ b/backend/api/EventHandlers/MqttEventHandler.cs @@ -100,15 +100,16 @@ private async void OnIsarStatus(object? sender, MqttReceivedArgs mqttArgs) _updateRobotSemaphore.WaitOne(); _logger.LogDebug("Semaphore acquired for updating robot status"); - var updatedRobot = await RobotService.UpdateRobotStatus(robot.Id, isarStatus.Status); + await RobotService.UpdateRobotStatus(robot.Id, isarStatus.Status); + robot.Status = isarStatus.Status; _updateRobotSemaphore.Release(); _logger.LogDebug("Semaphore released after updating robot status"); - _logger.LogInformation("Updated status for robot {Name} to {Status}", updatedRobot.Name, updatedRobot.Status); + _logger.LogInformation("Updated status for robot {Name} to {Status}", robot.Name, robot.Status); - _logger.LogInformation("OnIsarStatus: Robot {robotName} has status {robotStatus} and current inspection area {areaName}", updatedRobot.Name, updatedRobot.Status, updatedRobot.CurrentInspectionArea?.Name); + _logger.LogInformation("OnIsarStatus: Robot {robotName} has status {robotStatus} and current inspection area {areaName}", robot.Name, robot.Status, robot.CurrentInspectionArea?.Name); if (isarStatus.Status == RobotStatus.Available) { diff --git a/backend/api/Services/IsarService.cs b/backend/api/Services/IsarService.cs index 37caef005..039592144 100644 --- a/backend/api/Services/IsarService.cs +++ b/backend/api/Services/IsarService.cs @@ -57,6 +57,9 @@ public async Task StartMission(Robot robot, MissionRun missionRun) if (!response.IsSuccessStatusCode) { + if (response.StatusCode == HttpStatusCode.Conflict) + throw new RobotBusyException("Robot was not available when starting mission"); + (string message, int statusCode) = GetErrorDescriptionFoFailedIsarRequest(response); string errorResponse = await response.Content.ReadAsStringAsync(); logger.LogError("{Message}: {ErrorResponse}", message, errorResponse); diff --git a/backend/api/Services/MissionSchedulingService.cs b/backend/api/Services/MissionSchedulingService.cs index f0a6c6c7d..fb8816b43 100644 --- a/backend/api/Services/MissionSchedulingService.cs +++ b/backend/api/Services/MissionSchedulingService.cs @@ -114,6 +114,9 @@ or MissionRunNotFoundException ); await missionRunService.SetMissionRunToFailed(missionRun.Id, $"Mission run '{missionRun.Id}' was not started successfully. '{ex.Message}'"); } + catch (RobotBusyException) + { + } } public async Task HandleBatteryAndPressureLevel(Robot robot) diff --git a/backend/api/Utilities/Exceptions.cs b/backend/api/Utilities/Exceptions.cs index df3b5a085..1d929616f 100644 --- a/backend/api/Utilities/Exceptions.cs +++ b/backend/api/Utilities/Exceptions.cs @@ -91,6 +91,10 @@ public class RobotNotAvailableException(string message) : Exception(message) { } + public class RobotBusyException(string message) : Exception(message) + { + } + public class RobotNotInSameInstallationAsMissionException(string message) : Exception(message) { }