From bf441a94d673eabe6ad66d39086580e50f6c543d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Chirico=20Indreb=C3=B8?= Date: Mon, 16 Dec 2024 15:29:09 +0100 Subject: [PATCH] Improve mission starting stability --- .../api/Services/MissionSchedulingService.cs | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/backend/api/Services/MissionSchedulingService.cs b/backend/api/Services/MissionSchedulingService.cs index 203862386..cf1546dfe 100644 --- a/backend/api/Services/MissionSchedulingService.cs +++ b/backend/api/Services/MissionSchedulingService.cs @@ -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; @@ -452,32 +452,8 @@ private async Task StartMissionRun(MissionRun queuedMissionRun) return ongoingMissions; } - private async Task 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);