Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Commit a4b237d

Browse files
ap-git-hubhathind-ms
authored andcommitted
Save stats for all simulations when multiple sims are running (#307)
1 parent d4443bb commit a4b237d

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

SimulationAgent/Agent.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,28 +240,30 @@ private async Task StopInactiveSimulationsAsync(IList<Simulation> activeSimulati
240240

241241
private async Task SaveSimulationStatisticsAsync(IList<Simulation> simulations)
242242
{
243-
foreach (var simulation in simulations)
243+
DateTimeOffset now = DateTimeOffset.UtcNow;
244+
TimeSpan duration = now - this.lastSaveStatisticsTime;
245+
246+
// Save statistics for simulations at specified interval
247+
if (duration.Seconds >= SAVE_STATS_INTERVAL_SECS)
244248
{
245-
try
249+
foreach (var simulation in simulations)
246250
{
247-
if (this.simulationManagers.ContainsKey(simulation.Id))
251+
try
248252
{
249-
DateTimeOffset now = DateTimeOffset.UtcNow;
250-
TimeSpan duration = now - this.lastSaveStatisticsTime;
251-
252-
// Save simulation statistics at specified interval
253-
if (duration.Seconds >= SAVE_STATS_INTERVAL_SECS)
253+
if (this.simulationManagers.ContainsKey(simulation.Id))
254254
{
255-
await this.simulationManagers[simulation.Id].SaveStatisticsAsync();
256-
257-
this.lastSaveStatisticsTime = now;
255+
{
256+
await this.simulationManagers[simulation.Id].SaveStatisticsAsync();
257+
}
258258
}
259259
}
260+
catch (Exception e)
261+
{
262+
this.log.Error("Failed to save simulation statistics.", () => new { simulation.Id, e });
263+
}
260264
}
261-
catch (Exception e)
262-
{
263-
this.log.Error("Failed to save simulation statistics.", () => new { simulation.Id, e });
264-
}
265+
266+
this.lastSaveStatisticsTime = now;
265267
}
266268
}
267269

0 commit comments

Comments
 (0)