From ea9768b1f2b2fbb212e00e4fbd994dc3166d6fb7 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Thu, 13 Feb 2025 10:50:12 +0000 Subject: [PATCH] check tokens more aggressively when doing operations --- Sdk/Speckle.Connectors.Common/Operations/ReceiveOperation.cs | 3 +++ Sdk/Speckle.Connectors.Common/Operations/SendOperation.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Sdk/Speckle.Connectors.Common/Operations/ReceiveOperation.cs b/Sdk/Speckle.Connectors.Common/Operations/ReceiveOperation.cs index 9d2fd00ae..fe7a3cd03 100644 --- a/Sdk/Speckle.Connectors.Common/Operations/ReceiveOperation.cs +++ b/Sdk/Speckle.Connectors.Common/Operations/ReceiveOperation.cs @@ -26,6 +26,7 @@ public sealed class ReceiveOperation( ) { using var execute = activityFactory.Start("Receive Operation"); + cancellationToken.ThrowIfCancellationRequested(); execute?.SetTag("receiveInfo", receiveInfo); // 2 - Check account exist Account account = accountService.GetAccountWithServerUrlFallback(receiveInfo.AccountId, receiveInfo.ServerUrl); @@ -34,6 +35,7 @@ public sealed class ReceiveOperation( var version = await apiClient.Version.Get(receiveInfo.SelectedVersionId, receiveInfo.ProjectId, cancellationToken); + cancellationToken.ThrowIfCancellationRequested(); var commitObject = await threadContext.RunOnWorkerAsync( () => ReceiveData(account, version, receiveInfo, onOperationProgressed, cancellationToken) ); @@ -47,6 +49,7 @@ public sealed class ReceiveOperation( ) .ConfigureAwait(false); + cancellationToken.ThrowIfCancellationRequested(); await apiClient.Version.Received( new(version.id, receiveInfo.ProjectId, receiveInfo.SourceApplication), cancellationToken diff --git a/Sdk/Speckle.Connectors.Common/Operations/SendOperation.cs b/Sdk/Speckle.Connectors.Common/Operations/SendOperation.cs index 8751efc24..840e29da7 100644 --- a/Sdk/Speckle.Connectors.Common/Operations/SendOperation.cs +++ b/Sdk/Speckle.Connectors.Common/Operations/SendOperation.cs @@ -31,8 +31,10 @@ public sealed class SendOperation( CancellationToken ct = default ) { + ct.ThrowIfCancellationRequested(); var buildResult = await rootObjectBuilder.Build(objects, sendInfo, onOperationProgressed, ct); + ct.ThrowIfCancellationRequested(); // POC: Jonathon asks on behalf of willow twin - let's explore how this can work // buildResult.RootObject["@report"] = new Report { ConversionResults = buildResult.ConversionResults }; @@ -42,6 +44,7 @@ public sealed class SendOperation( var (rootObjId, convertedReferences) = await threadContext.RunOnWorkerAsync( () => Send(buildResult.RootObject, sendInfo, onOperationProgressed, ct) ); + ct.ThrowIfCancellationRequested(); return new(rootObjId, convertedReferences, buildResult.ConversionResults); }