From a9ccd4fac84e422498ec99afba89129be753ae1c Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Mon, 18 Dec 2023 16:12:25 +0100 Subject: [PATCH] Add 'Noop' method to WorkflowExecutionContext A Noop method has been added to the WorkflowExecutionContext, and is now assigned to the ExecuteDelegate field when no resumption point is specified. The change, will prevent the invocation of the regular "ExecuteAsync" method, closing the activity without additional operations. --- .../Elsa.Workflows.Core/Contexts/WorkflowExecutionContext.cs | 1 + .../Extensions/WorkflowExecutionContextExtensions.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/Elsa.Workflows.Core/Contexts/WorkflowExecutionContext.cs b/src/modules/Elsa.Workflows.Core/Contexts/WorkflowExecutionContext.cs index 02ba5a09f..c89137274 100644 --- a/src/modules/Elsa.Workflows.Core/Contexts/WorkflowExecutionContext.cs +++ b/src/modules/Elsa.Workflows.Core/Contexts/WorkflowExecutionContext.cs @@ -33,6 +33,7 @@ public class WorkflowExecutionContext : IExecutionContext private static readonly object ActivityOutputRegistryKey = new(); private static readonly object LastActivityResultKey = new(); internal static ValueTask Complete(ActivityExecutionContext context) => context.CompleteActivityAsync(); + internal static ValueTask Noop(ActivityExecutionContext context) => default; private readonly IList _completionCallbackEntries = new List(); private IList _activityExecutionContexts; private readonly IHasher _hasher; diff --git a/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs b/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs index ee24f57cd..77b31b1b1 100644 --- a/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs +++ b/src/modules/Elsa.Workflows.Core/Extensions/WorkflowExecutionContextExtensions.cs @@ -76,8 +76,8 @@ public static class WorkflowExecutionContextExtensions }; workflowExecutionContext.Scheduler.Schedule(workItem); - // If no resumption point was specified, use "Complete" to prevent the regular "ExecuteAsync" method to be invoked and instead complete the activity. - workflowExecutionContext.ExecuteDelegate = bookmark.CallbackMethodName != null ? bookmarkedActivity.GetResumeActivityDelegate(bookmark.CallbackMethodName) : WorkflowExecutionContext.Complete; + // If no resumption point was specified, use a "noop" to prevent the regular "ExecuteAsync" method to be invoked and instead complete the activity. + workflowExecutionContext.ExecuteDelegate = bookmark.CallbackMethodName != null ? bookmarkedActivity.GetResumeActivityDelegate(bookmark.CallbackMethodName) : WorkflowExecutionContext.Noop; // Store the bookmark to resume in the context. workflowExecutionContext.ResumedBookmarkContext = new ResumedBookmarkContext(bookmark);