Fix unsubscribe + reduce bot update db query
This commit is contained in:
@@ -67,11 +67,25 @@ public class CandleStoreGrain : Grain, ICandleStoreGrain, IAsyncObserver<Candle>
|
||||
|
||||
public override async Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
|
||||
{
|
||||
// Unsubscribe from the stream
|
||||
// Unsubscribe from the stream with proper error handling
|
||||
if (_streamSubscription != null)
|
||||
{
|
||||
await _streamSubscription.UnsubscribeAsync();
|
||||
_streamSubscription = null;
|
||||
try
|
||||
{
|
||||
await _streamSubscription.UnsubscribeAsync();
|
||||
_logger.LogDebug("Successfully unsubscribed from stream for grain {GrainKey}", this.GetPrimaryKeyString());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Log the error but don't throw - this is common during shutdown when
|
||||
// the pub-sub rendezvous grain may already be deactivated
|
||||
_logger.LogWarning(ex, "Failed to unsubscribe from stream during deactivation for grain {GrainKey}. This is normal during shutdown.",
|
||||
this.GetPrimaryKeyString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
_streamSubscription = null;
|
||||
}
|
||||
}
|
||||
|
||||
await base.OnDeactivateAsync(reason, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user