Fix lastStartTime update
This commit is contained in:
@@ -174,10 +174,11 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
_state.State.StartupTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
// Track runtime: set LastStartTime when bot starts and clear LastStopTime
|
||||
_state.State.LastStartTime = DateTime.UtcNow;
|
||||
_state.State.LastStopTime = null;
|
||||
|
||||
if (previousStatus != BotStatus.Running)
|
||||
{
|
||||
_state.State.LastStartTime = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
await _state.WriteStateAsync();
|
||||
|
||||
// Start the in-memory timer and persistent reminder
|
||||
@@ -217,6 +218,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
await _state.WriteStateAsync();
|
||||
await SaveBotAsync(BotStatus.Running);
|
||||
}
|
||||
|
||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} is already running", this.GetPrimaryKey());
|
||||
return;
|
||||
}
|
||||
@@ -304,8 +306,9 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
_state.State.AccumulatedRunTimeSeconds += currentSessionSeconds;
|
||||
_state.State.LastStopTime = DateTime.UtcNow;
|
||||
_state.State.LastStartTime = null; // Clear since bot is no longer running
|
||||
|
||||
_logger.LogInformation("Bot {GrainId} accumulated {Seconds} seconds of runtime. Total: {TotalSeconds} seconds",
|
||||
|
||||
_logger.LogInformation(
|
||||
"Bot {GrainId} accumulated {Seconds} seconds of runtime. Total: {TotalSeconds} seconds",
|
||||
this.GetPrimaryKey(), currentSessionSeconds, _state.State.AccumulatedRunTimeSeconds);
|
||||
}
|
||||
|
||||
@@ -781,7 +784,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Unable to load user for bot {BotId} while saving stats", _state.State.Identifier);
|
||||
_logger.LogWarning(ex, "Unable to load user for bot {BotId} while saving stats",
|
||||
_state.State.Identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user