Skip to content

Commit

Permalink
delay deactivation to max value
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleLittleCloud committed Jul 14, 2024
1 parent 597bd95 commit 1b270ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 32 deletions.
17 changes: 1 addition & 16 deletions ChatRoom/ChatRoom.Common/Orleans/ChannelGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,14 @@ public ChannelGrain(
{
_logger = logger;
_config = config;
this.DelayDeactivation(TimeSpan.MaxValue);
}

public override async Task OnActivateAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Channel {ChannelId} activated", this.GetPrimaryKeyString());
}

public override Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
{
if (reason.ReasonCode == DeactivationReasonCode.ActivationIdle)
{
_logger?.LogInformation("Channel {ChannelId} deactivated due to inactivity", this.GetPrimaryKeyString());
_logger?.LogInformation("Delaying deactivation for 30 seconds");
this.DelayDeactivation(TimeSpan.FromSeconds(30));

return Task.CompletedTask;
}

var roomID = this.GetPrimaryKeyString();
_logger?.LogInformation($"Channel {roomID} deactivated because {reason.Description} and {reason.ReasonCode}");
return base.OnDeactivateAsync(reason, cancellationToken);
}

public async Task Delete()
{
_logger.LogInformation("Channel {ChannelId} deactivated", this.GetPrimaryKeyString());
Expand Down
17 changes: 1 addition & 16 deletions ChatRoom/ChatRoom.Common/Orleans/RoomGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,10 @@ public RoomGrain(
ILogger<RoomGrain>? logger = null)
: base()
{
this.DelayDeactivation(TimeSpan.MaxValue);
_logger = logger;
}

public override Task OnDeactivateAsync(DeactivationReason reason, CancellationToken cancellationToken)
{
if (reason.ReasonCode == DeactivationReasonCode.ActivationIdle)
{
_logger?.LogInformation("Room {RoomName} deactivated due to inactivity", this.GrainKey);
_logger?.LogInformation("Delaying deactivation for 30 seconds");
this.DelayDeactivation(TimeSpan.FromSeconds(30));

return Task.CompletedTask;
}

var roomID = this.GetPrimaryKeyString();
_logger?.LogInformation($"Room {roomID} deactivated because {reason.Description} and {reason.ReasonCode}");
return base.OnDeactivateAsync(reason, cancellationToken);
}

public virtual string GrainKey => this.GetPrimaryKeyString();

public Task<AgentInfo[]> GetMembers() => Task.FromResult(_agents.Keys.ToArray());
Expand Down

0 comments on commit 1b270ae

Please sign in to comment.