Skip to content

Commit 731a80b

Browse files
committed
Split up function
1 parent ef441b2 commit 731a80b

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

backend/api/EventHandlers/MqttEventHandler.cs

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,39 @@ private async void OnIsarStatus(object? sender, MqttReceivedArgs mqttArgs)
129129
_updateRobotSemaphore.Release();
130130
_logger.LogDebug("Semaphore released after updating robot current mission id");
131131
}
132-
MissionScheduling.TriggerRobotAvailable(new RobotAvailableEventArgs(robot.Id));
132+
await MissionScheduling.StartNextMissionRunIfSystemIsAvailable(robot.Id);
133+
}
134+
}
135+
136+
private async void CreateRobot(IsarRobotInfoMessage isarRobotInfo, Installation installation)
137+
{
138+
_logger.LogInformation(
139+
"Received message from new ISAR instance '{Id}' with robot name '{Name}'. Adding new robot to database",
140+
isarRobotInfo.IsarId, isarRobotInfo.RobotName);
141+
142+
var robotQuery = new CreateRobotQuery
143+
{
144+
IsarId = isarRobotInfo.IsarId,
145+
Name = isarRobotInfo.RobotName,
146+
RobotType = isarRobotInfo.RobotType,
147+
SerialNumber = isarRobotInfo.SerialNumber,
148+
CurrentInstallationCode = installation.InstallationCode,
149+
Documentation = isarRobotInfo.DocumentationQueries,
150+
Host = isarRobotInfo.Host,
151+
Port = isarRobotInfo.Port,
152+
RobotCapabilities = isarRobotInfo.Capabilities,
153+
Status = RobotStatus.Available,
154+
};
155+
156+
try
157+
{
158+
var newRobot = await RobotService.CreateFromQuery(robotQuery);
159+
_logger.LogInformation("Added robot '{RobotName}' with ISAR id '{IsarId}' to database", newRobot.Name, newRobot.IsarId);
160+
}
161+
catch (DbUpdateException)
162+
{
163+
_logger.LogError($"Failed to add robot {robotQuery.Name} with to the database");
164+
return;
133165
}
134166
}
135167

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

155187
if (robot == null)
156188
{
157-
_logger.LogInformation(
158-
"Received message from new ISAR instance '{Id}' with robot name '{Name}'. Adding new robot to database",
159-
isarRobotInfo.IsarId, isarRobotInfo.RobotName);
160-
161-
var robotQuery = new CreateRobotQuery
162-
{
163-
IsarId = isarRobotInfo.IsarId,
164-
Name = isarRobotInfo.RobotName,
165-
RobotType = isarRobotInfo.RobotType,
166-
SerialNumber = isarRobotInfo.SerialNumber,
167-
CurrentInstallationCode = installation.InstallationCode,
168-
Documentation = isarRobotInfo.DocumentationQueries,
169-
Host = isarRobotInfo.Host,
170-
Port = isarRobotInfo.Port,
171-
RobotCapabilities = isarRobotInfo.Capabilities,
172-
Status = RobotStatus.Available,
173-
};
174-
175-
try
176-
{
177-
var newRobot = await RobotService.CreateFromQuery(robotQuery);
178-
_logger.LogInformation("Added robot '{RobotName}' with ISAR id '{IsarId}' to database", newRobot.Name, newRobot.IsarId);
179-
}
180-
catch (DbUpdateException)
181-
{
182-
_logger.LogError($"Failed to add robot {robotQuery.Name} with to the database");
183-
return;
184-
}
185-
189+
CreateRobot(isarRobotInfo, installation);
186190
return;
187191
}
188192

0 commit comments

Comments
 (0)