Update bot registry when bot status in db is running
This commit is contained in:
@@ -50,19 +50,27 @@ public class BotReminderInitializerGrain : Grain, IBotReminderInitializerGrain,
|
|||||||
|
|
||||||
_logger.LogInformation("Found {Count} running bots to reactivate", runningBots.Count());
|
_logger.LogInformation("Found {Count} running bots to reactivate", runningBots.Count());
|
||||||
|
|
||||||
|
var botRegistry = GrainFactory.GetGrain<ILiveBotRegistryGrain>(0);
|
||||||
|
|
||||||
// Ping each running bot to reactivate it and ensure reminders are registered
|
// Ping each running bot to reactivate it and ensure reminders are registered
|
||||||
var tasks = runningBots.Select(async bot =>
|
var tasks = runningBots.Select(async bot =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Pinging bot {BotId} ({BotName}) to reactivate", bot.Identifier, bot.Name);
|
_logger.LogDebug("Reactivating bot {BotId} ({BotName})", bot.Identifier, bot.Name);
|
||||||
|
|
||||||
|
// First, update the bot status in the registry to Running
|
||||||
|
await botRegistry.UpdateBotStatus(bot.Identifier, BotStatus.Running);
|
||||||
|
|
||||||
|
_logger.LogDebug("Updated registry status to Running for bot {BotId} ({BotName})", bot.Identifier, bot.Name);
|
||||||
|
|
||||||
|
// Then ping the bot to reactivate it
|
||||||
var grain = GrainFactory.GetGrain<ILiveTradingBotGrain>(bot.Identifier);
|
var grain = GrainFactory.GetGrain<ILiveTradingBotGrain>(bot.Identifier);
|
||||||
var success = await grain.PingAsync();
|
var success = await grain.PingAsync();
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
_logger.LogDebug("Successfully pinged bot {BotId} ({BotName})", bot.Identifier, bot.Name);
|
_logger.LogDebug("Successfully reactivated bot {BotId} ({BotName})", bot.Identifier, bot.Name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -71,7 +79,7 @@ public class BotReminderInitializerGrain : Grain, IBotReminderInitializerGrain,
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Failed to ping bot {BotId} ({BotName})", bot.Identifier, bot.Name);
|
_logger.LogError(ex, "Failed to reactivate bot {BotId} ({BotName})", bot.Identifier, bot.Name);
|
||||||
SentrySdk.CaptureException(ex);
|
SentrySdk.CaptureException(ex);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user