Skip to content

Commit

Permalink
Fix misguiding logging for ISAR mqtt callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
GodVenn committed Jun 10, 2022
1 parent 80c1358 commit 86d4c9f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
51 changes: 27 additions & 24 deletions backend/api/EventHandlers/MqttEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,16 @@ private async void OnMissionUpdate(object? sender, MqttReceivedArgs mqttArgs)
return;
}

await _reportService.UpdateMissionStatus(mission.MissionId, status);
bool success = await _reportService.UpdateMissionStatus(mission.MissionId, status);

_logger.LogInformation(
"{time} - Mission {id} updated to {status} for {robot}",
mission.Timestamp,
mission.MissionId,
mission.Status,
mission.RobotId
);
if (success)
_logger.LogInformation(
"{time} - Mission {id} updated to {status} for {robot}",
mission.Timestamp,
mission.MissionId,
mission.Status,
mission.RobotId
);
}

private async void OnTaskUpdate(object? sender, MqttReceivedArgs mqttArgs)
Expand All @@ -80,15 +81,16 @@ private async void OnTaskUpdate(object? sender, MqttReceivedArgs mqttArgs)
return;
}

await _reportService.UpdateTaskStatus(task.TaskId, status);
bool success = await _reportService.UpdateTaskStatus(task.TaskId, status);

_logger.LogInformation(
"{time} - Task {id} updated to {status} for {robot}",
task.Timestamp,
task.TaskId,
task.Status,
task.RobotId
);
if (success)
_logger.LogInformation(
"{time} - Task {id} updated to {status} for {robot}",
task.Timestamp,
task.TaskId,
task.Status,
task.RobotId
);
}

private async void OnStepUpdate(object? sender, MqttReceivedArgs mqttArgs)
Expand All @@ -109,15 +111,16 @@ private async void OnStepUpdate(object? sender, MqttReceivedArgs mqttArgs)
return;
}

await _reportService.UpdateStepStatus(step.StepId, status);
bool success = await _reportService.UpdateStepStatus(step.StepId, status);

_logger.LogInformation(
"{time} - Step {id} updated to {status} for {robot}",
step.Timestamp,
step.StepId,
step.Status,
step.RobotId
);
if (success)
_logger.LogInformation(
"{time} - Step {id} updated to {status} for {robot}",
step.Timestamp,
step.StepId,
step.Status,
step.RobotId
);
}
}
}
18 changes: 12 additions & 6 deletions backend/api/Services/ReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task<IEnumerable<Report>> ReadAll()
);
}

public async Task UpdateMissionStatus(string isarMissionId, ReportStatus reportStatus)
public async Task<bool> UpdateMissionStatus(string isarMissionId, ReportStatus reportStatus)
{
var report = await ReadByIsarMissionId(isarMissionId);
if (report is null)
Expand All @@ -90,15 +90,17 @@ public async Task UpdateMissionStatus(string isarMissionId, ReportStatus reportS
"Could not update mission status for ISAR mission with id: {id} as the report was not found",
isarMissionId
);
return;
return false;
}

report.ReportStatus = reportStatus;

await _context.SaveChangesAsync();

return true;
}

public async Task UpdateTaskStatus(string isarTaskId, IsarTaskStatus taskStatus)
public async Task<bool> UpdateTaskStatus(string isarTaskId, IsarTaskStatus taskStatus)
{
var task = await ReadIsarTaskById(isarTaskId);
if (task is null)
Expand All @@ -107,15 +109,17 @@ public async Task UpdateTaskStatus(string isarTaskId, IsarTaskStatus taskStatus)
"Could not update task status for ISAR task with id: {id} as the task was not found",
isarTaskId
);
return;
return false;
}

task.TaskStatus = taskStatus;

await _context.SaveChangesAsync();

return true;
}

public async Task UpdateStepStatus(string isarStepId, IsarStepStatus stepStatus)
public async Task<bool> UpdateStepStatus(string isarStepId, IsarStepStatus stepStatus)
{
var step = await ReadIsarStepById(isarStepId);
if (step is null)
Expand All @@ -124,12 +128,14 @@ public async Task UpdateStepStatus(string isarStepId, IsarStepStatus stepStatus)
"Could not update step status for ISAR step with id: {id} as the step was not found",
isarStepId
);
return;
return false;
}

step.StepStatus = stepStatus;

await _context.SaveChangesAsync();

return true;
}
}
}

0 comments on commit 86d4c9f

Please sign in to comment.