Skip to content

Commit

Permalink
Pass robot in OnMissionRunCreated
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Jan 2, 2025
1 parent d2fc422 commit 1c892d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
8 changes: 3 additions & 5 deletions backend/api.test/EventHandlers/TestMissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,14 @@ public async Task QueuedMissionsAreNotAbortedWhenRobotAvailableHappensAtTheSameT
inspectionArea,
true
);
Thread.Sleep(100);
var missionRun2 = await _databaseUtilities.NewMissionRun(
installation.InstallationCode,
robot,
inspectionArea,
true
);
Thread.Sleep(100);

var missionRunCreatedEventArgs = new MissionRunCreatedEventArgs(missionRun1.Id);
var missionRunCreatedEventArgs = new MissionRunCreatedEventArgs(missionRun1);
_missionRunService.RaiseEvent(
nameof(MissionRunService.MissionRunCreated),
missionRunCreatedEventArgs
Expand Down Expand Up @@ -599,7 +597,7 @@ public async Task QueuedContinuesWhenOnIsarStatusHappensAtTheSameTimeAsOnIsarMis
);
Thread.Sleep(100);

var missionRunCreatedEventArgs = new MissionRunCreatedEventArgs(missionRun1.Id);
var missionRunCreatedEventArgs = new MissionRunCreatedEventArgs(missionRun1);
_missionRunService.RaiseEvent(
nameof(MissionRunService.MissionRunCreated),
missionRunCreatedEventArgs
Expand Down Expand Up @@ -691,7 +689,7 @@ public async Task ReturnHomeMissionAbortedIfNewMissionScheduled()
Thread.Sleep(100);

// Act
var eventArgs = new MissionRunCreatedEventArgs(missionRun.Id);
var eventArgs = new MissionRunCreatedEventArgs(missionRun);
_missionRunService.RaiseEvent(nameof(MissionRunService.MissionRunCreated), eventArgs);
Thread.Sleep(500);

Expand Down
16 changes: 7 additions & 9 deletions backend/api/EventHandlers/MissionEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,19 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)

private async void OnMissionRunCreated(object? sender, MissionRunCreatedEventArgs e)
{
_logger.LogInformation(
"Triggered MissionRunCreated event for mission run ID: {MissionRunId}",
e.MissionRunId
);
var missionRun = e.MissionRun;

var missionRun = await MissionService.ReadById(e.MissionRunId, readOnly: true);
if (missionRun == null)
{
_logger.LogError(
"Mission run with ID: {MissionRunId} was not found in the database",
e.MissionRunId
);
_logger.LogError("OnMissionRunCreated was triggered with null Robot value");
return;
}

_logger.LogInformation(
"Triggered MissionRunCreated event for mission run ID: {MissionRunId}",
missionRun.Id
);

_startMissionSemaphore.WaitOne();

if (
Expand Down
4 changes: 2 additions & 2 deletions backend/api/Services/Events/MissionEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Api.Services.Events
{
public class MissionRunCreatedEventArgs(string missionRunId) : EventArgs
public class MissionRunCreatedEventArgs(MissionRun missionRun) : EventArgs
{
public string MissionRunId { get; } = missionRunId;
public MissionRun MissionRun { get; } = missionRun;
}

public class RobotAvailableEventArgs(Robot robot) : EventArgs
Expand Down
6 changes: 3 additions & 3 deletions backend/api/Services/MissionRunService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,11 @@ public async Task<MissionRun> Create(
new MissionRunResponse(missionRun)
);

DetachTracking(missionRun);

if (triggerCreatedMissionRunEvent)
{
var args = new MissionRunCreatedEventArgs(missionRun.Id);
var args = new MissionRunCreatedEventArgs(missionRun);
OnMissionRunCreated(args);
}

Expand All @@ -152,8 +154,6 @@ public async Task<MissionRun> Create(
logger.LogInformation($"Mission run created by user with Id {userInfo.Id}");
}

DetachTracking(missionRun);

return missionRun;
}

Expand Down

0 comments on commit 1c892d5

Please sign in to comment.