From af9862440f9fc96c0fbcb527fdeadf3688f6901e Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sat, 30 Dec 2023 20:13:49 +0100 Subject: [PATCH] Improve handling of non-HTTP context in HttpEndpoint Updated the HttpEndpoint class to handle non-HTTP contexts better. Instead of throwing an exception when it finds itself in a non-HTTP context, it now creates a bookmark that allows the invoker to save the state and resume execution from there. A callback has also been added to the bookmarks creation process to prepare for resumption actions. --- src/modules/Elsa.Http/Activities/HttpEndpoint.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/modules/Elsa.Http/Activities/HttpEndpoint.cs b/src/modules/Elsa.Http/Activities/HttpEndpoint.cs index 978ff6c83..ed94e5e90 100644 --- a/src/modules/Elsa.Http/Activities/HttpEndpoint.cs +++ b/src/modules/Elsa.Http/Activities/HttpEndpoint.cs @@ -166,7 +166,7 @@ public class HttpEndpoint : Trigger if (!context.IsTriggerOfWorkflow()) { - context.CreateBookmarks(GetBookmarkPayloads(context.ExpressionExecutionContext), includeActivityInstanceId: false); + context.CreateBookmarks(GetBookmarkPayloads(context.ExpressionExecutionContext), includeActivityInstanceId: false, callback: OnResumeAsync); return; } @@ -191,8 +191,10 @@ public class HttpEndpoint : Trigger if (httpContext == null) { - // We're not in an HTTP context, so let's fail. - throw new Exception("Cannot execute in a non-HTTP context"); + // We're executing in a non-HTTP context (e.g. in a virtual actor). + // Create a bookmark to allow the invoker to export the state and resume execution from there. + context.CreateBookmark(OnResumeAsync, BookmarkMetadata.HttpCrossBoundary); + return; } await HandleRequestAsync(context, httpContext);