From 014a3ed7e526022e3446ab2615b03efb49fcea64 Mon Sep 17 00:00:00 2001 From: cryptooda Date: Sun, 28 Sep 2025 23:34:56 +0700 Subject: [PATCH] Fix agent count --- scripts/safe-migrate.sh | 4 ++-- .../Grains/IPlatformSummaryGrain.cs | 2 +- src/Managing.Application/Bots/Grains/AgentGrain.cs | 2 +- src/Managing.Application/Grains/PlatformSummaryGrain.cs | 9 ++------- src/Managing.Application/Users/UserService.cs | 2 -- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/scripts/safe-migrate.sh b/scripts/safe-migrate.sh index 6847c728..95fa6c96 100755 --- a/scripts/safe-migrate.sh +++ b/scripts/safe-migrate.sh @@ -82,11 +82,11 @@ log "🚀 Starting safe migration for environment: $ENVIRONMENT" # Validate environment case $ENVIRONMENT in - "Development"|"Sandbox"|"Production"|"Oda") + "Development"|"SandboxLocal"|"Production"|"Oda") log "✅ Environment '$ENVIRONMENT' is valid" ;; *) - error "❌ Invalid environment '$ENVIRONMENT'. Use: Development, Sandbox, Production, or Oda" + error "❌ Invalid environment '$ENVIRONMENT'. Use: Development, SandboxLocal, Production, or Oda" ;; esac diff --git a/src/Managing.Application.Abstractions/Grains/IPlatformSummaryGrain.cs b/src/Managing.Application.Abstractions/Grains/IPlatformSummaryGrain.cs index 62ff0ea6..6c8f329d 100644 --- a/src/Managing.Application.Abstractions/Grains/IPlatformSummaryGrain.cs +++ b/src/Managing.Application.Abstractions/Grains/IPlatformSummaryGrain.cs @@ -30,7 +30,7 @@ public interface IPlatformSummaryGrain : IGrainWithStringKey /// Increments the total agent count when a new agent is activated /// [OneWay] - Task IncrementAgentCountAsync(); + Task RefreshAgentCountAsync(); [OneWay] Task OnPositionClosedAsync(PositionClosedEvent evt); diff --git a/src/Managing.Application/Bots/Grains/AgentGrain.cs b/src/Managing.Application/Bots/Grains/AgentGrain.cs index 211e758b..d15da937 100644 --- a/src/Managing.Application/Bots/Grains/AgentGrain.cs +++ b/src/Managing.Application/Bots/Grains/AgentGrain.cs @@ -92,7 +92,7 @@ public class AgentGrain : Grain, IAgentGrain await ServiceScopeHelpers.WithScopedService(_scopeFactory, async grainFactory => { var platformGrain = grainFactory.GetGrain("platform-summary"); - await platformGrain.IncrementAgentCountAsync(); + await platformGrain.RefreshAgentCountAsync(); _logger.LogDebug("Notified platform summary about new agent activation for user {UserId}", userId); }); } diff --git a/src/Managing.Application/Grains/PlatformSummaryGrain.cs b/src/Managing.Application/Grains/PlatformSummaryGrain.cs index 01fefc83..68deed0d 100644 --- a/src/Managing.Application/Grains/PlatformSummaryGrain.cs +++ b/src/Managing.Application/Grains/PlatformSummaryGrain.cs @@ -81,7 +81,6 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable _logger.LogInformation("Created initial empty daily snapshot for {Date}", today); } - _state.State.TotalAgents = await _agentService.GetTotalAgentCount(); await RefreshDataAsync(); } @@ -219,16 +218,12 @@ public class PlatformSummaryGrain : Grain, IPlatformSummaryGrain, IRemindable } } - public async Task IncrementAgentCountAsync() + public async Task RefreshAgentCountAsync() { try { - _logger.LogInformation("Incrementing agent count from {CurrentCount} to {NewCount}", - _state.State.TotalAgents, _state.State.TotalAgents + 1); - - _state.State.TotalAgents++; + _state.State.TotalAgents = await _agentService.GetTotalAgentCount(); await _state.WriteStateAsync(); - _logger.LogInformation("Agent count incremented to: {NewCount}", _state.State.TotalAgents); } catch (Exception ex) diff --git a/src/Managing.Application/Users/UserService.cs b/src/Managing.Application/Users/UserService.cs index b462335a..21271250 100644 --- a/src/Managing.Application/Users/UserService.cs +++ b/src/Managing.Application/Users/UserService.cs @@ -116,8 +116,6 @@ public class UserService : IUserService var agentGrain = _grainFactory.GetGrain(user.Id); await agentGrain.InitializeAsync(user.Id, string.Empty); _logger.LogInformation("AgentGrain initialized for new user {UserId}", user.Id); - - } catch (Exception ex) {