Skip to content

Commit

Permalink
Refactor mission run priority to type
Browse files Browse the repository at this point in the history
  • Loading branch information
mrica-equinor committed Apr 12, 2024
1 parent 9954431 commit b142c36
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 22 deletions.
6 changes: 3 additions & 3 deletions backend/api.test/Database/DatabaseUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<MissionRun> NewMissionRun(
Robot robot,
Area area,
bool writeToDatabase = false,
MissionRunPriority missionRunPriority = MissionRunPriority.Normal,
MissionRunType missionRunType = MissionRunType.Normal,
MissionStatus missionStatus = MissionStatus.Pending,
string? isarMissionId = null
)
Expand All @@ -51,15 +51,15 @@ public async Task<MissionRun> NewMissionRun(
Robot = robot,
MissionId = null,
IsarMissionId = isarMissionId,
MissionRunPriority = missionRunPriority,
MissionRunType = missionRunType,
Status = missionStatus,
DesiredStartTime = DateTime.Now,
Area = area,
Tasks = [],
Map = new MapMetadata(),
InstallationCode = installationCode
};
if (missionRunPriority == MissionRunPriority.Localization)
if (missionRunType == MissionRunType.Localization)
{
missionRun.Tasks = new List<MissionTask>
{
Expand Down
4 changes: 2 additions & 2 deletions backend/api.test/EventHandlers/TestMissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public async void QueuedMissionsAreAbortedWhenLocalizationFails()
var deck = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck.Name);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Available, installation, area);
var localizationMissionRun = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunPriority.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString());
var localizationMissionRun = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunType.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString());
var missionRun1 = await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true);

Thread.Sleep(100);
Expand Down Expand Up @@ -342,7 +342,7 @@ public async void LocalizationMissionCompletesAfterPressingSendToSafeZoneButton(
var deck = await _databaseUtilities.NewDeck(installation.InstallationCode, plant.PlantCode);
var area = await _databaseUtilities.NewArea(installation.InstallationCode, plant.PlantCode, deck.Name);
var robot = await _databaseUtilities.NewRobot(RobotStatus.Busy, installation, area);
await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunPriority.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString());
await _databaseUtilities.NewMissionRun(installation.InstallationCode, robot, area, true, MissionRunType.Localization, MissionStatus.Ongoing, Guid.NewGuid().ToString());

Thread.Sleep(100);

Expand Down
6 changes: 3 additions & 3 deletions backend/api/Controllers/MissionSchedulingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery
Robot = robot,
MissionId = missionRun.MissionId,
Status = MissionStatus.Pending,
MissionRunPriority = MissionRunPriority.Normal,
MissionRunType = MissionRunType.Normal,
Tasks = missionTasks,
DesiredStartTime = scheduledMissionQuery.DesiredStartTime ?? DateTime.UtcNow,
InstallationCode = missionRun.InstallationCode,
Expand Down Expand Up @@ -156,7 +156,7 @@ [FromBody] ScheduleMissionQuery scheduledMissionQuery
Robot = robot,
MissionId = missionDefinition.Id,
Status = MissionStatus.Pending,
MissionRunPriority = MissionRunPriority.Normal,
MissionRunType = MissionRunType.Normal,
DesiredStartTime = scheduledMissionQuery.DesiredStartTime ?? DateTime.UtcNow,
Tasks = missionTasks,
InstallationCode = missionDefinition.InstallationCode,
Expand Down Expand Up @@ -317,7 +317,7 @@ [FromBody] ScheduledMissionQuery scheduledMissionQuery
Robot = robot,
MissionId = scheduledMissionDefinition.Id,
Status = MissionStatus.Pending,
MissionRunPriority = MissionRunPriority.Normal,
MissionRunType = MissionRunType.Normal,
DesiredStartTime = scheduledMissionQuery.DesiredStartTime ?? DateTime.UtcNow,
Tasks = missionTasks,
InstallationCode = scheduledMissionQuery.InstallationCode,
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Controllers/Models/MissionRunResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MissionRunResponse

public MapMetadata? Map { get; set; }

public MissionRunPriority MissionRunPriority { get; set; }
public MissionRunType MissionRunType { get; set; }

[JsonConstructor]
#nullable disable
Expand All @@ -67,7 +67,7 @@ public MissionRunResponse(MissionRun mission)
EstimatedDuration = mission.EstimatedDuration;
Tasks = mission.Tasks;
Map = mission.Map;
MissionRunPriority = mission.MissionRunPriority;
MissionRunType = mission.MissionRunType;
}

}
Expand Down
6 changes: 3 additions & 3 deletions backend/api/Database/Models/MissionRun.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IList<MissionTask> Tasks
}

[Required]
public MissionRunPriority MissionRunPriority { get; set; }
public MissionRunType MissionRunType { get; set; }

[MaxLength(200)]
public string? IsarMissionId { get; set; }
Expand Down Expand Up @@ -207,10 +207,10 @@ public enum MissionStatus
PartiallySuccessful
}

public enum MissionRunPriority
public enum MissionRunType
{
Normal,
Response,
ReturnHome,
Emergency,
Localization
}
Expand Down
2 changes: 1 addition & 1 deletion backend/api/EventHandlers/MissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private async void OnMissionCompleted(object? sender, MissionCompletedEventArgs
var lastMissionRun = await MissionService.ReadLastExecutedMissionRunByRobotWithoutTracking(robot.Id);
if (lastMissionRun != null)
{
if (lastMissionRun.MissionRunPriority == MissionRunPriority.Emergency & lastMissionRun.Status == MissionStatus.Successful)
if (lastMissionRun.MissionRunType == MissionRunType.Emergency & lastMissionRun.Status == MissionStatus.Successful)
{
_logger.LogInformation("Return to safe zone mission on robot {RobotName} was successful.", robot.Name);
SignalRService.ReportSafeZoneSuccessToSignalR(robot, $"Robot {robot.Name} is in the safe zone");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public async Task<MissionRun> QueueCustomMissionRun(CustomMissionQuery customMis
Comment = customMissionQuery.Comment,
Robot = robot,
Status = MissionStatus.Pending,
MissionRunPriority = MissionRunPriority.Normal,
MissionRunType = MissionRunType.Normal,
DesiredStartTime = customMissionQuery.DesiredStartTime ?? DateTime.UtcNow,
Tasks = missionTasks,
InstallationCode = customMissionQuery.InstallationCode,
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Services/LocalizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public async Task<MissionRun> CreateLocalizationMissionInArea(string robotId, st
{
Name = "Localization mission",
Robot = robot,
MissionRunPriority = MissionRunPriority.Localization,
MissionRunType = MissionRunType.Localization,
InstallationCode = area.Installation.InstallationCode,
Area = area,
Status = MissionStatus.Pending,
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Services/MissionRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ public async Task<IList<MissionRun>> ReadMissionRunQueue(string robotId)
return await GetMissionRunsWithSubModels()
.OrderBy(missionRun => missionRun.DesiredStartTime)
.FirstOrDefaultAsync(missionRun =>
missionRun.Robot.Id == robotId && missionRun.MissionRunPriority == MissionRunPriority.Emergency && missionRun.Status == MissionStatus.Pending);
missionRun.Robot.Id == robotId && missionRun.MissionRunType == MissionRunType.Emergency && missionRun.Status == MissionStatus.Pending);
}

public async Task<MissionRun?> ReadNextScheduledLocalizationMissionRun(string robotId)
{
var nextScheduledMissionRun = await GetMissionRunsWithSubModels()
.OrderBy(missionRun => missionRun.DesiredStartTime)
.FirstOrDefaultAsync(missionRun => missionRun.Robot.Id == robotId && missionRun.Status == MissionStatus.Pending && missionRun.MissionRunPriority == MissionRunPriority.Localization);
.FirstOrDefaultAsync(missionRun => missionRun.Robot.Id == robotId && missionRun.Status == MissionStatus.Pending && missionRun.MissionRunType == MissionRunType.Localization);

return nextScheduledMissionRun;
}
Expand Down
6 changes: 3 additions & 3 deletions backend/api/Services/MissionSchedulingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public async Task ScheduleMissionToDriveToSafePosition(string robotId, string ar
{
Name = "Drive to Safe Position",
Robot = robot,
MissionRunPriority = MissionRunPriority.Emergency,
MissionRunType = MissionRunType.Emergency,
InstallationCode = area.Installation.InstallationCode,
Area = area,
Status = MissionStatus.Pending,
Expand Down Expand Up @@ -306,7 +306,7 @@ private async Task MoveInterruptedMissionsToQueue(IEnumerable<string> interrupte
{
Name = missionRun.Name,
Robot = missionRun.Robot,
MissionRunPriority = missionRun.MissionRunPriority,
MissionRunType = missionRun.MissionRunType,
InstallationCode = missionRun.Area!.Installation.InstallationCode,
Area = missionRun.Area,
Status = MissionStatus.Pending,
Expand Down Expand Up @@ -450,7 +450,7 @@ private async Task<bool> TheSystemIsAvailableToRunAMission(string robotId, strin
throw new MissionRunNotFoundException(errorMessage);
}

if (robot.MissionQueueFrozen && missionRun.MissionRunPriority != MissionRunPriority.Emergency && missionRun.MissionRunPriority != MissionRunPriority.Localization)
if (robot.MissionQueueFrozen && missionRun.MissionRunType != MissionRunType.Emergency && missionRun.MissionRunType != MissionRunType.Localization)
{
logger.LogInformation("Mission run {MissionRunId} was not started as the mission run queue for robot {RobotName} is frozen", missionRun.Id, robot.Name);
return false;
Expand Down
2 changes: 1 addition & 1 deletion backend/api/Services/ReturnToHomeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private async Task<MissionRun> ScheduleReturnToHomeMissionRun(string robotId)
Name = "Return to home mission",
Robot = robot,
InstallationCode = robot.CurrentInstallation.InstallationCode,
MissionRunPriority = MissionRunPriority.Normal,
MissionRunType = MissionRunType.ReturnHome,
Area = robot.CurrentArea,
Status = MissionStatus.Pending,
DesiredStartTime = DateTime.UtcNow,
Expand Down

0 comments on commit b142c36

Please sign in to comment.