Update status to match UI
This commit is contained in:
@@ -131,7 +131,7 @@ public class AgentGrain : Grain, IAgentGrain, IRemindable
|
||||
Losses = totalLosses,
|
||||
TotalROI = totalROI,
|
||||
Runtime = runtime,
|
||||
ActiveStrategiesCount = bots.Count(b => b.Status == BotStatus.Up),
|
||||
ActiveStrategiesCount = bots.Count(b => b.Status == BotStatus.Running),
|
||||
TotalVolume = totalVolume,
|
||||
};
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
||||
|
||||
// O(1) FIX: Decrement the counters based on the removed entry's status
|
||||
_state.State.TotalBotsCount--;
|
||||
if (entryToRemove.Status == BotStatus.Up)
|
||||
if (entryToRemove.Status == BotStatus.Running)
|
||||
{
|
||||
_state.State.ActiveBotsCount--;
|
||||
}
|
||||
@@ -140,11 +140,11 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
||||
}
|
||||
|
||||
// O(1) FIX: Conditionally adjust the counter
|
||||
if (newStatus == BotStatus.Up && previousStatus != BotStatus.Up)
|
||||
if (newStatus == BotStatus.Running && previousStatus != BotStatus.Running)
|
||||
{
|
||||
_state.State.ActiveBotsCount++;
|
||||
}
|
||||
else if (newStatus != BotStatus.Up && previousStatus == BotStatus.Up)
|
||||
else if (newStatus != BotStatus.Running && previousStatus == BotStatus.Running)
|
||||
{
|
||||
_state.State.ActiveBotsCount--;
|
||||
}
|
||||
@@ -171,7 +171,7 @@ public class LiveBotRegistryGrain : Grain, ILiveBotRegistryGrain
|
||||
if (!_state.State.Bots.TryGetValue(identifier, out var entry))
|
||||
{
|
||||
_logger.LogWarning("Bot {Identifier} is not registered in the registry, returning None", identifier);
|
||||
return Task.FromResult(BotStatus.None);
|
||||
return Task.FromResult(BotStatus.Saved);
|
||||
}
|
||||
|
||||
return Task.FromResult(entry.Status);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
var agentGrain = GrainFactory.GetGrain<IAgentGrain>(user.Id);
|
||||
await agentGrain.RegisterBotAsync(_state.State.Identifier);
|
||||
|
||||
await SaveBotAsync(BotStatus.None);
|
||||
await SaveBotAsync(BotStatus.Saved);
|
||||
|
||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} created successfully", this.GetPrimaryKey());
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} activated. Registry status: {Status}",
|
||||
botId, botStatus);
|
||||
|
||||
if (botStatus == BotStatus.Up && _tradingBot == null)
|
||||
if (botStatus == BotStatus.Running && _tradingBot == null)
|
||||
{
|
||||
// Now, we can proceed with resuming the bot.
|
||||
await ResumeBotInternalAsync();
|
||||
@@ -124,8 +124,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
await RegisterReminder();
|
||||
|
||||
// Update both database and registry status
|
||||
await SaveBotAsync(BotStatus.Up);
|
||||
await UpdateBotRegistryStatus(BotStatus.Up);
|
||||
await SaveBotAsync(BotStatus.Running);
|
||||
await UpdateBotRegistryStatus(BotStatus.Running);
|
||||
|
||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} resumed successfully", this.GetPrimaryKey());
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
{
|
||||
_logger.LogError(ex, "Failed to resume bot {GrainId}", this.GetPrimaryKey());
|
||||
_tradingBot = null; // Clean up on failure
|
||||
await UpdateBotRegistryStatus(BotStatus.Down);
|
||||
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
var status = await botRegistry.GetBotStatus(botId);
|
||||
|
||||
// Check if already running
|
||||
if (status == BotStatus.Up && _tradingBot != null)
|
||||
if (status == BotStatus.Running && _tradingBot != null)
|
||||
{
|
||||
await RegisterReminder();
|
||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} is already running", this.GetPrimaryKey());
|
||||
@@ -162,7 +162,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
{
|
||||
_logger.LogError(ex, "Failed to start LiveTradingBotGrain {GrainId}", this.GetPrimaryKey());
|
||||
// Ensure registry status is correct on failure
|
||||
await UpdateBotRegistryStatus(BotStatus.Down);
|
||||
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -197,7 +197,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
// The check is now against the registry status
|
||||
var botRegistry = GrainFactory.GetGrain<ILiveBotRegistryGrain>(0);
|
||||
var botStatus = await botRegistry.GetBotStatus(this.GetPrimaryKey());
|
||||
if (botStatus == BotStatus.Down)
|
||||
if (botStatus == BotStatus.Stopped)
|
||||
{
|
||||
_logger.LogInformation("Bot {GrainId} is already stopped", this.GetPrimaryKey());
|
||||
return;
|
||||
@@ -211,10 +211,10 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
// Sync state from the volatile TradingBotBase before destroying it
|
||||
SyncStateFromBase();
|
||||
await _state.WriteStateAsync();
|
||||
await SaveBotAsync(BotStatus.Down);
|
||||
await SaveBotAsync(BotStatus.Stopped);
|
||||
_tradingBot = null;
|
||||
|
||||
await UpdateBotRegistryStatus(BotStatus.Down);
|
||||
await UpdateBotRegistryStatus(BotStatus.Stopped);
|
||||
_logger.LogInformation("LiveTradingBotGrain {GrainId} stopped successfully", this.GetPrimaryKey());
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -297,7 +297,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
|
||||
await _state.WriteStateAsync();
|
||||
|
||||
// Save bot statistics to database
|
||||
await SaveBotAsync(BotStatus.Up);
|
||||
await SaveBotAsync(BotStatus.Running);
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user