Removed reminder when stopped

This commit is contained in:
2025-09-15 01:54:51 +07:00
parent e33a596c67
commit 5216a0ae87

View File

@@ -102,6 +102,12 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
// Now, we can proceed with resuming the bot. // Now, we can proceed with resuming the bot.
await ResumeBotInternalAsync(botStatus); await ResumeBotInternalAsync(botStatus);
} }
else if (botStatus == BotStatus.Stopped)
{
// If the status is stopped, ensure the reminder is unregistered
await UnregisterReminder();
_logger.LogInformation("LiveTradingBotGrain {GrainId} status is stopped, reminder unregistered", botId);
}
} }
private async Task ResumeBotInternalAsync(BotStatus previousStatus) private async Task ResumeBotInternalAsync(BotStatus previousStatus)
@@ -172,8 +178,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
private async Task RegisterReminder() private async Task RegisterReminder()
{ {
var reminderPeriod = TimeSpan.FromMinutes(2); await this.RegisterOrUpdateReminder(_reminderName, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(5));
await this.RegisterOrUpdateReminder(_reminderName, reminderPeriod, reminderPeriod);
} }
/// <summary> /// <summary>
@@ -185,7 +190,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
if (_timer != null) return; if (_timer != null) return;
var botOptions = GrainHelpers.GetDynamicRandomizedTimerOptions(TimeSpan.FromMinutes(1), 20); var botOptions = GrainHelpers.GetDynamicRandomizedTimerOptions(TimeSpan.FromMinutes(1), 100);
_timer = this.RegisterGrainTimer( _timer = this.RegisterGrainTimer(
async _ => await ExecuteBotCycle(), async _ => await ExecuteBotCycle(),
@@ -205,6 +210,7 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
if (botStatus == BotStatus.Stopped) if (botStatus == BotStatus.Stopped)
{ {
_logger.LogInformation("Bot {GrainId} is already stopped", this.GetPrimaryKey()); _logger.LogInformation("Bot {GrainId} is already stopped", this.GetPrimaryKey());
await UnregisterReminder();
return; return;
} }