Await HTTP resume callbacks
This commit is contained in:
parent
2dcd852833
commit
4f092ee5e4
|
|
@ -163,7 +163,7 @@ public class HttpEndpoint : Trigger<HttpRequest>
|
|||
{
|
||||
var path = Path.Get(context);
|
||||
var methods = SupportedMethods.GetOrDefault(context) ?? new List<string> { HttpMethods.Get };
|
||||
context.WaitForHttpRequest(path, methods, OnResumeAsync);
|
||||
await context.WaitForHttpRequest(path, methods, OnResumeAsync);
|
||||
}
|
||||
|
||||
private async ValueTask OnResumeAsync(ActivityExecutionContext context)
|
||||
|
|
@ -175,8 +175,8 @@ public class HttpEndpoint : Trigger<HttpRequest>
|
|||
{
|
||||
// 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.CreateCrossBoundaryBookmark();
|
||||
return;
|
||||
await context.CreateCrossBoundaryBookmark();
|
||||
return;
|
||||
}
|
||||
|
||||
await HandleRequestAsync(context);
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ public abstract class HttpEndpointBase<TResult> : Trigger<TResult>
|
|||
{
|
||||
}
|
||||
|
||||
protected override void Execute(ActivityExecutionContext context)
|
||||
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context)
|
||||
{
|
||||
var options = GetOptions();
|
||||
context.WaitForHttpRequest(options, HttpRequestReceivedAsync);
|
||||
await context.WaitForHttpRequest(options, HttpRequestReceivedAsync);
|
||||
}
|
||||
|
||||
protected override IEnumerable<object> GetTriggerPayloads(TriggerIndexingContext context)
|
||||
|
|
|
|||
|
|
@ -3,33 +3,34 @@ using Elsa.Extensions;
|
|||
using Elsa.Http.Bookmarks;
|
||||
using Elsa.Workflows;
|
||||
using Elsa.Workflows.Models;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Routing.Patterns;
|
||||
|
||||
namespace Elsa.Http.Extensions;
|
||||
|
||||
public static class HttpEndpointActivityExecutionContextExtensions
|
||||
{
|
||||
public static void WaitForHttpRequest(this ActivityExecutionContext context, string path, string method, ExecuteActivityDelegate? callback = null)
|
||||
public static async ValueTask WaitForHttpRequest(this ActivityExecutionContext context, string path, string method, ExecuteActivityDelegate? callback = null)
|
||||
{
|
||||
var options = new HttpEndpointOptions
|
||||
{
|
||||
var options = new HttpEndpointOptions
|
||||
{
|
||||
Path = path,
|
||||
Methods = [method]
|
||||
};
|
||||
WaitForHttpRequest(context, options, callback);
|
||||
}
|
||||
Path = path,
|
||||
Methods = [method]
|
||||
};
|
||||
await WaitForHttpRequest(context, options, callback);
|
||||
}
|
||||
|
||||
public static void WaitForHttpRequest(this ActivityExecutionContext context, string path, IEnumerable<string> methods, ExecuteActivityDelegate? callback = null)
|
||||
public static async ValueTask WaitForHttpRequest(this ActivityExecutionContext context, string path, IEnumerable<string> methods, ExecuteActivityDelegate? callback = null)
|
||||
{
|
||||
var options = new HttpEndpointOptions
|
||||
{
|
||||
var options = new HttpEndpointOptions
|
||||
{
|
||||
Path = path,
|
||||
Methods = methods.ToList()
|
||||
};
|
||||
WaitForHttpRequest(context, options, callback);
|
||||
}
|
||||
Path = path,
|
||||
Methods = methods.ToList()
|
||||
};
|
||||
await WaitForHttpRequest(context, options, callback);
|
||||
}
|
||||
|
||||
public static void WaitForHttpRequest(this ActivityExecutionContext context, HttpEndpointOptions options, ExecuteActivityDelegate? callback = null)
|
||||
public static async ValueTask WaitForHttpRequest(this ActivityExecutionContext context, HttpEndpointOptions options, ExecuteActivityDelegate? callback = null)
|
||||
{
|
||||
var path = options.Path;
|
||||
if (path.Contains("//"))
|
||||
|
|
@ -42,7 +43,8 @@ public static class HttpEndpointActivityExecutionContextExtensions
|
|||
return;
|
||||
}
|
||||
|
||||
callback?.Invoke(context);
|
||||
if (callback is not null)
|
||||
await callback(context);
|
||||
}
|
||||
|
||||
public static IEnumerable<object> GetHttpEndpointStimuli(this TriggerIndexingContext context, string path, string method)
|
||||
|
|
@ -81,7 +83,7 @@ public static class HttpEndpointActivityExecutionContextExtensions
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
internal static void CreateCrossBoundaryBookmark(this ActivityExecutionContext context, ExecuteActivityDelegate? callback = null)
|
||||
internal static ValueTask CreateCrossBoundaryBookmark(this ActivityExecutionContext context, ExecuteActivityDelegate? callback = null)
|
||||
{
|
||||
var bookmarkOptions = new CreateBookmarkArgs
|
||||
{
|
||||
|
|
@ -90,5 +92,6 @@ public static class HttpEndpointActivityExecutionContextExtensions
|
|||
Metadata = BookmarkMetadata.HttpCrossBoundary,
|
||||
};
|
||||
context.CreateBookmark(bookmarkOptions);
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue