Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cancelling session from sessions service cancel tasks and abort results from the session #789

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Common/src/Storage/ResultTableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ await resultTable.UpdateManyResults(result => result.OwnerTaskId == ownerTaskId,
ownerTaskId);
}

/// <summary>
/// Abort the results of the given session
/// </summary>
/// <param name="resultTable">Interface to manage results</param>
/// <param name="sessionId">id of the session containing the results</param>
/// <param name="cancellationToken">Token used to cancel the execution of the method</param>
/// <returns>
/// Task representing the asynchronous execution of the method
/// </returns>
public static async Task AbortSessionResults(this IResultTable resultTable,
string sessionId,
CancellationToken cancellationToken = default)
{
await resultTable.UpdateManyResults(result => result.SessionId == sessionId && result.Status == ResultStatus.Created,
new UpdateDefinition<Result>().Set(data => data.Status,
ResultStatus.Aborted),
cancellationToken)
.ConfigureAwait(false);

resultTable.Logger.LogDebug("Abort results from {session}",
sessionId);
}


/// <summary>
/// Updates in bulk results
Expand Down
13 changes: 10 additions & 3 deletions Common/src/gRPC/Services/GrpcSessionsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@ public override async Task<CancelSessionResponse> CancelSession(CancelSessionReq
using var measure = meter_.CountAndTime();
try
{
var tasks = taskTable_.CancelSessionAsync(request.SessionId,
context.CancellationToken);
var results = resultTable_.AbortSessionResults(request.SessionId,
context.CancellationToken);
var sessions = sessionTable_.CancelSessionAsync(request.SessionId,
context.CancellationToken);

await tasks.ConfigureAwait(false);
await results.ConfigureAwait(false);
return new CancelSessionResponse
{
Session = (await sessionTable_.CancelSessionAsync(request.SessionId,
context.CancellationToken)
.ConfigureAwait(false)).ToGrpcSessionRaw(),
Session = (await sessions.ConfigureAwait(false)).ToGrpcSessionRaw(),
};
}
catch (SessionNotFoundException e)
Expand Down
Loading