Fix long time update AgentName

This commit is contained in:
2025-09-17 14:47:28 +07:00
parent cee3902a4d
commit 98fdfb9793
3 changed files with 51 additions and 7 deletions

View File

@@ -51,8 +51,33 @@ public class AgentGrain : Grain, IAgentGrain
{
_state.State.AgentName = agentName;
await _state.WriteStateAsync();
await UpdateSummary();
_logger.LogInformation("Agent {UserId} initialized with name {AgentName}", userId, agentName);
// Create an empty AgentSummary for the new agent
var emptySummary = new AgentSummary
{
UserId = userId,
AgentName = agentName,
TotalPnL = 0,
TotalROI = 0,
Wins = 0,
Losses = 0,
Runtime = null,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow,
ActiveStrategiesCount = 0,
TotalVolume = 0,
TotalBalance = 0
};
await _agentService.SaveOrUpdateAgentSummary(emptySummary);
_logger.LogInformation("Agent {UserId} initialized with name {AgentName} and empty summary", userId, agentName);
}
public async Task UpdateAgentNameAsync(string agentName)
{
_state.State.AgentName = agentName;
await _state.WriteStateAsync();
_logger.LogInformation("Agent {UserId} updated with name {AgentName}", this.GetPrimaryKeyLong(), agentName);
}
public async Task OnAgentSummaryUpdateAsync(AgentSummaryUpdateEvent updateEvent)