Skip to content

Commit

Permalink
Split up function
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Dec 13, 2024
1 parent 2997500 commit dedc8d8
Showing 1 changed file with 34 additions and 30 deletions.
64 changes: 34 additions & 30 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,39 @@ private async void OnIsarStatus(object? sender, MqttReceivedArgs mqttArgs)
_updateRobotSemaphore.Release();
_logger.LogDebug("Semaphore released after updating robot current mission id");
}
MissionScheduling.TriggerRobotAvailable(new RobotAvailableEventArgs(robot.Id));
await MissionScheduling.StartNextMissionRunIfSystemIsAvailable(robot.Id);
}
}

private async void CreateRobot(IsarRobotInfoMessage isarRobotInfo, Installation installation)
{
_logger.LogInformation(
"Received message from new ISAR instance '{Id}' with robot name '{Name}'. Adding new robot to database",
isarRobotInfo.IsarId, isarRobotInfo.RobotName);

var robotQuery = new CreateRobotQuery
{
IsarId = isarRobotInfo.IsarId,
Name = isarRobotInfo.RobotName,
RobotType = isarRobotInfo.RobotType,
SerialNumber = isarRobotInfo.SerialNumber,
CurrentInstallationCode = installation.InstallationCode,
Documentation = isarRobotInfo.DocumentationQueries,
Host = isarRobotInfo.Host,
Port = isarRobotInfo.Port,
RobotCapabilities = isarRobotInfo.Capabilities,
Status = RobotStatus.Available,
};

try
{
var newRobot = await RobotService.CreateFromQuery(robotQuery);
_logger.LogInformation("Added robot '{RobotName}' with ISAR id '{IsarId}' to database", newRobot.Name, newRobot.IsarId);
}
catch (DbUpdateException)
{
_logger.LogError($"Failed to add robot {robotQuery.Name} with to the database");
return;
}
}

Expand All @@ -154,35 +186,7 @@ private async void OnIsarRobotInfo(object? sender, MqttReceivedArgs mqttArgs)

if (robot == null)
{
_logger.LogInformation(
"Received message from new ISAR instance '{Id}' with robot name '{Name}'. Adding new robot to database",
isarRobotInfo.IsarId, isarRobotInfo.RobotName);

var robotQuery = new CreateRobotQuery
{
IsarId = isarRobotInfo.IsarId,
Name = isarRobotInfo.RobotName,
RobotType = isarRobotInfo.RobotType,
SerialNumber = isarRobotInfo.SerialNumber,
CurrentInstallationCode = installation.InstallationCode,
Documentation = isarRobotInfo.DocumentationQueries,
Host = isarRobotInfo.Host,
Port = isarRobotInfo.Port,
RobotCapabilities = isarRobotInfo.Capabilities,
Status = RobotStatus.Available,
};

try
{
var newRobot = await RobotService.CreateFromQuery(robotQuery);
_logger.LogInformation("Added robot '{RobotName}' with ISAR id '{IsarId}' to database", newRobot.Name, newRobot.IsarId);
}
catch (DbUpdateException)
{
_logger.LogError($"Failed to add robot {robotQuery.Name} with to the database");
return;
}

CreateRobot(isarRobotInfo, installation);
return;
}

Expand Down

0 comments on commit dedc8d8

Please sign in to comment.