Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenBond committed May 11, 2024
1 parent 53b2248 commit 0750f0c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/Orleans.Core.Abstractions/Timers/TimerCreationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ namespace Orleans.Runtime;
public bool Interleave { get; init; }

/// <summary>
/// Gets a value indicating whether callbacks scheduled by this timer should keep the grain activation active. Defaults to <see langword="false"/>.
/// Gets a value indicating whether callbacks scheduled by this timer should extend the lifetime of the grain activation. Defaults to <see langword="false"/>.
/// </summary>
/// <remarks>
/// If this value is <see langword="false"/>, timer callbacks will not extend a grain activation's lifetime.
/// If a grain is only processing timer callbacks and no other messages, the grain will be collected after its idle collection period expires.
/// If this value is <see langword="true"/>, timer callback will extend a grain activation's lifetime.
/// If the timer period is shorter than the grain's idle collection period, the grain will not be collected due to idleness.
/// </remarks>
public bool KeepAlive { get; init; }

}
18 changes: 12 additions & 6 deletions src/Orleans.Runtime/Timers/GrainTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ protected void ScheduleTickOnActivation()
_grainContext.ReceiveMessage(msg);
}

protected abstract Task InvokeCallback();

private ValueTask<Response> InvokeTickAsync(CancellationToken cancellationToken)
{
try
Expand All @@ -110,16 +112,20 @@ private ValueTask<Response> InvokeTickAsync(CancellationToken cancellationToken)
// If the task is not completed, we need to await the tick asynchronously.
if (task is { IsCompletedSuccessfully: false })
{
// Complete asynchronously.
return AwaitCallbackTask(task, cancellationToken);
}

if (Logger.IsEnabled(LogLevel.Trace))
else
{
Logger.LogTrace((int)ErrorCode.TimerAfterCallback, "Completed timer callback for timer {TimerName}", this);
// Complete synchronously.
if (Logger.IsEnabled(LogLevel.Trace))
{
Logger.LogTrace((int)ErrorCode.TimerAfterCallback, "Completed timer callback for timer {TimerName}", this);
}

OnTickCompleted();
return new(Response.Completed);
}

OnTickCompleted();
return new(Response.Completed);
}
catch (Exception exc)
{
Expand Down

0 comments on commit 0750f0c

Please sign in to comment.