Fix stop/restart
This commit is contained in:
@@ -174,7 +174,18 @@ namespace Managing.Application.ManageBot
|
||||
bot.User = user;
|
||||
// Config is already set correctly from backup data, so we only need to restore signals, positions, etc.
|
||||
bot.LoadBackup(backupBot);
|
||||
bot.Start();
|
||||
|
||||
// Only start the bot if the backup status is Up
|
||||
if (backupBot.LastStatus == BotStatus.Up)
|
||||
{
|
||||
// Start the bot asynchronously without waiting for completion
|
||||
_ = Task.Run(() => bot.Start());
|
||||
}
|
||||
else
|
||||
{
|
||||
// Keep the bot in Down status if it was originally Down
|
||||
bot.Stop();
|
||||
}
|
||||
}
|
||||
|
||||
public IBot CreateSimpleBot(string botName, Workflow workflow)
|
||||
@@ -246,12 +257,15 @@ namespace Managing.Application.ManageBot
|
||||
{
|
||||
// Stop the bot first to ensure clean state
|
||||
bot.Stop();
|
||||
|
||||
|
||||
// Small delay to ensure stop is complete
|
||||
await Task.Delay(100);
|
||||
|
||||
|
||||
// Restart the bot (this will update StartupTime)
|
||||
bot.Restart();
|
||||
|
||||
// Start the bot asynchronously without waiting for completion
|
||||
_ = Task.Run(() => bot.Start());
|
||||
|
||||
var restartMessage = $"🔄 **Bot Restarted**\n\n" +
|
||||
$"🎯 **Agent:** {bot.User.AgentName}\n" +
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class ToggleIsForWatchingCommand : IRequest<string>
|
||||
public class RestartBotCommand : IRequest<string>
|
||||
{
|
||||
public string Name { get; }
|
||||
public BotType BotType { get; }
|
||||
|
||||
public ToggleIsForWatchingCommand(string name)
|
||||
public RestartBotCommand(BotType botType, string name)
|
||||
{
|
||||
BotType = botType;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
using MediatR;
|
||||
using static Managing.Common.Enums;
|
||||
|
||||
namespace Managing.Application.ManageBot.Commands
|
||||
{
|
||||
public class RestartBotCommand : IRequest<string>
|
||||
public class ToggleIsForWatchingCommand : IRequest<string>
|
||||
{
|
||||
public string Name { get; }
|
||||
public BotType BotType { get; }
|
||||
|
||||
public RestartBotCommand(BotType botType, string name)
|
||||
public ToggleIsForWatchingCommand(string name)
|
||||
{
|
||||
BotType = botType;
|
||||
Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,6 @@ public class LoadBackupBotCommandHandler : IRequestHandler<LoadBackupBotCommand,
|
||||
{
|
||||
try
|
||||
{
|
||||
if (backupBot.LastStatus == BotStatus.Down)
|
||||
{
|
||||
_logger.LogInformation("Skipping backup bot {Identifier} as it is marked as Down.",
|
||||
backupBot.Identifier);
|
||||
continue;
|
||||
}
|
||||
|
||||
var activeBot = _botService.GetActiveBots().FirstOrDefault(b => b.Identifier == backupBot.Identifier);
|
||||
|
||||
if (activeBot == null)
|
||||
@@ -61,10 +54,20 @@ public class LoadBackupBotCommandHandler : IRequestHandler<LoadBackupBotCommand,
|
||||
.FirstOrDefault(b => b.Identifier == backupBot.Identifier);
|
||||
if (activeBot != null)
|
||||
{
|
||||
result[activeBot.Identifier] = BotStatus.Up;
|
||||
anyBackupStarted = true;
|
||||
_logger.LogInformation("Backup bot {Identifier} started successfully.",
|
||||
backupBot.Identifier);
|
||||
// Check if the bot was originally Down
|
||||
if (backupBot.LastStatus == BotStatus.Down)
|
||||
{
|
||||
result[activeBot.Identifier] = BotStatus.Down;
|
||||
_logger.LogInformation("Backup bot {Identifier} loaded but kept in Down status as it was originally Down.",
|
||||
backupBot.Identifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
result[activeBot.Identifier] = BotStatus.Up;
|
||||
anyBackupStarted = true;
|
||||
_logger.LogInformation("Backup bot {Identifier} started successfully.",
|
||||
backupBot.Identifier);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user