Fix reminding for livetradingbot

This commit is contained in:
2025-09-18 12:19:52 +07:00
parent f1bb40fb75
commit ffe69356d8
8 changed files with 199 additions and 10 deletions

View File

@@ -43,8 +43,8 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
public override async Task OnActivateAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("LiveTradingBotGrain {GrainId} activated", this.GetPrimaryKey());
await base.OnActivateAsync(cancellationToken);
await ResumeBotIfRequiredAsync();
await base.OnActivateAsync(cancellationToken);
}
public override async Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
@@ -795,4 +795,27 @@ public class LiveTradingBotGrain : Grain, ILiveTradingBotGrain, IRemindable
_logger.LogError(ex, "Failed to send swap notification for bot {BotId}", _tradingBot?.Identifier);
}
}
/// <summary>
/// Pings the bot to reactivate it and ensure reminders are registered
/// Used during startup to reactivate bots that may have lost their reminders
/// The grain activation will automatically handle reminder registration
/// </summary>
public Task<bool> PingAsync()
{
try
{
_logger.LogInformation("Ping received for LiveTradingBotGrain {GrainId}", this.GetPrimaryKey());
// The grain activation (OnActivateAsync) will automatically call ResumeBotIfRequiredAsync()
// which handles checking the registry status and re-registering reminders if needed
// So we just need to return true to indicate the ping was received
return Task.FromResult(true);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during ping for LiveTradingBotGrain {GrainId}", this.GetPrimaryKey());
return Task.FromResult(false);
}
}
}