Skip to content

Commit

Permalink
Improve mission starting stability
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Dec 16, 2024
1 parent 4ff7a1f commit bf441a9
Showing 1 changed file with 2 additions and 26 deletions.
28 changes: 2 additions & 26 deletions backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public async Task StartNextMissionRunIfSystemIsAvailable(Robot robot)

if (missionRun == null) { return; }

if (!await TheSystemIsAvailableToRunAMission(robot.Id, missionRun.Id))
if (!TheSystemIsAvailableToRunAMission(robot, missionRun))
{
logger.LogInformation("Mission {MissionRunId} was put on the queue as the system may not start a mission now", missionRun.Id);
return;
Expand Down Expand Up @@ -452,32 +452,8 @@ private async Task StartMissionRun(MissionRun queuedMissionRun)
return ongoingMissions;
}

private async Task<bool> TheSystemIsAvailableToRunAMission(string robotId, string missionRunId)
private bool TheSystemIsAvailableToRunAMission(Robot robot, MissionRun missionRun)
{
bool ongoingMission = await OngoingMission(robotId);

if (ongoingMission)
{
logger.LogInformation("Mission run {MissionRunId} was not started as there is already an ongoing mission", missionRunId);
return false;
}

var robot = await robotService.ReadById(robotId, readOnly: true);
if (robot is null)
{
string errorMessage = $"Robot with ID: {robotId} was not found in the database";
logger.LogError("{Message}", errorMessage);
throw new RobotNotFoundException(errorMessage);
}

var missionRun = await missionRunService.ReadById(missionRunId, readOnly: true);
if (missionRun is null)
{
string errorMessage = $"Mission run with Id {missionRunId} was not found in the database";
logger.LogError("{Message}", errorMessage);
throw new MissionRunNotFoundException(errorMessage);
}

if (robot.MissionQueueFrozen && missionRun.MissionRunType != MissionRunType.Emergency)
{
logger.LogInformation("Mission run {MissionRunId} was not started as the mission run queue for robot {RobotName} is frozen", missionRun.Id, robot.Name);
Expand Down

0 comments on commit bf441a9

Please sign in to comment.