Skip to content

Commit

Permalink
Stop mission if robot is idle
Browse files Browse the repository at this point in the history
If the robot is reported as idle from ISAR, stopping a mission should not crash
  • Loading branch information
Afonso-2403 committed Nov 10, 2023
1 parent 2b96357 commit bf5ae79
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions backend/api/Controllers/RobotController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,13 @@ public async Task<ActionResult> StopMission([FromRoute] string robotId)
_logger.LogError(e, "{Message}", Message);
return StatusCode(StatusCodes.Status500InternalServerError, Message);
}
catch (MissionNotFoundException)
{
_logger.LogWarning($"No mission was runnning for robot {robot.Id}");
robot.CurrentMissionId = null;
await _robotService.Update(robot);

}

try { await _robotService.SetCurrentMissionId(robotId, null); }
catch (RobotNotFoundException e) { return NotFound(e.Message); }
Expand Down
9 changes: 8 additions & 1 deletion backend/api/Services/IsarService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Net;
using System.Text.Json;
using Api.Database.Models;
using Api.Services.Models;
using Api.Utilities;
Expand Down Expand Up @@ -88,6 +89,12 @@ public async Task<IsarControlMissionResponse> StopMission(Robot robot)
{
(string message, int statusCode) = GetErrorDescriptionFoFailedIsarRequest(response);
string errorResponse = await response.Content.ReadAsStringAsync();
if (response.StatusCode == HttpStatusCode.Conflict && errorResponse.Contains("idle", StringComparison.CurrentCultureIgnoreCase))
{
_logger.LogError("No mission was running for robot '{Id}", robot.Id);
throw new MissionNotFoundException($"No mission was running for robot {robot.Id}");
}

_logger.LogError("{Message}: {ErrorResponse}", message, errorResponse);
throw new MissionException(message, statusCode);
}
Expand Down
2 changes: 2 additions & 0 deletions backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ public async Task StopCurrentMissionRun(string robotId)
throw new MissionException(Message, 0);
}

catch (MissionNotFoundException) { _logger.LogWarning($"No mission was running for robot {robot.Id}"); }

robot.CurrentMissionId = null;
await _robotService.Update(robot);
}
Expand Down

0 comments on commit bf5ae79

Please sign in to comment.