Skip to content

Commit

Permalink
Handle missions being scheduled at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Dec 17, 2024
1 parent 4f0f8db commit 3fdb1fa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 3 additions & 0 deletions backend/api/Services/IsarService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public async Task<IsarMission> 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);
Expand Down
3 changes: 3 additions & 0 deletions backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<MissionRun?> HandleBatteryAndPressureLevel(Robot robot)
Expand Down
4 changes: 4 additions & 0 deletions backend/api/Utilities/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}
Expand Down

0 comments on commit 3fdb1fa

Please sign in to comment.