update stats data

This commit is contained in:
2025-08-15 07:42:26 +07:00
parent 0a4a4e1398
commit 7528405845
8 changed files with 413 additions and 450 deletions

View File

@@ -65,8 +65,8 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
"Bot {Identifier} registered successfully for user {UserId}. Total bots: {TotalBots}, Active bots: {ActiveBots}",
identifier, userId, _state.State.TotalBotsCount, _state.State.ActiveBotsCount);
// Notify platform summary grain about strategy deployment
await NotifyStrategyDeployedAsync(identifier, userId);
// Notify platform summary grain about strategy count change
await NotifyPlatformSummaryAsync();
}
catch (Exception ex)
{
@@ -102,8 +102,8 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
"Bot {Identifier} unregistered successfully from user {UserId}. Total bots: {TotalBots}",
identifier, entryToRemove.UserId, _state.State.TotalBotsCount);
// Notify platform summary grain about strategy stopped
await NotifyStrategyStoppedAsync(identifier, entryToRemove.UserId);
// Notify platform summary grain about strategy count change
await NotifyPlatformSummaryAsync();
}
catch (Exception ex)
{
@@ -187,65 +187,19 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
return Task.FromResult(entry.Status);
}
private async Task NotifyStrategyDeployedAsync(Guid identifier, int userId)
private async Task NotifyPlatformSummaryAsync()
{
try
{
// Get bot details for the event
var bot = await _botService.GetBotByIdentifier(identifier);
if (bot != null)
{
var platformGrain = GrainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
var deployedEvent = new StrategyDeployedEvent
{
StrategyId = identifier,
AgentName = bot.User.AgentName,
StrategyName = bot.Name
};
await platformGrain.OnStrategyDeployedAsync(deployedEvent);
_logger.LogDebug("Notified platform summary about strategy deployment: {StrategyName}", bot.Name);
}
else
{
_logger.LogWarning("Could not find bot {Identifier} to notify platform summary", identifier);
}
var platformGrain = GrainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
await platformGrain.UpdateActiveStrategyCountAsync(_state.State.ActiveBotsCount);
_logger.LogDebug("Notified platform summary about active strategy count change. New count: {ActiveCount}",
_state.State.ActiveBotsCount);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to notify platform summary about strategy deployment for bot {Identifier}", identifier);
}
}
private async Task NotifyStrategyStoppedAsync(Guid identifier, int userId)
{
try
{
// Get bot details for the event
var bot = await _botService.GetBotByIdentifier(identifier);
if (bot != null)
{
var platformGrain = GrainFactory.GetGrain<IPlatformSummaryGrain>("platform-summary");
var stoppedEvent = new StrategyStoppedEvent
{
StrategyId = identifier,
AgentName = bot.User?.Name ?? $"User-{userId}",
StrategyName = bot.Name
};
await platformGrain.OnStrategyStoppedAsync(stoppedEvent);
_logger.LogDebug("Notified platform summary about strategy stopped: {StrategyName}", bot.Name);
}
else
{
_logger.LogWarning("Could not find bot {Identifier} to notify platform summary", identifier);
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to notify platform summary about strategy stopped for bot {Identifier}", identifier);
_logger.LogError(ex, "Failed to notify platform summary about strategy count change");
}
}
}