Skip to content

Commit

Permalink
Improve handling of non-HTTP context in HttpEndpoint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sfmskywalker committed Dec 30, 2023
1 parent 023ef26 commit af98624
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/modules/Elsa.Http/Activities/HttpEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected override async ValueTask ExecuteAsync(ActivityExecutionContext context

if (!context.IsTriggerOfWorkflow())
{
context.CreateBookmarks(GetBookmarkPayloads(context.ExpressionExecutionContext), includeActivityInstanceId: false);
context.CreateBookmarks(GetBookmarkPayloads(context.ExpressionExecutionContext), includeActivityInstanceId: false, callback: OnResumeAsync);
return;
}

Expand All @@ -191,8 +191,10 @@ private async ValueTask OnResumeAsync(ActivityExecutionContext context)

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);
Expand Down

0 comments on commit af98624

Please sign in to comment.