Enables activity test run to return results
Updates the activity test run endpoint to return activity execution results such as outputs, outcomes, exceptions, and status. This allows users to inspect the results of test runs for activities, providing valuable insights into their behavior.
This commit is contained in:
parent
e7fcf94b66
commit
2db059da3d
|
|
@ -1,6 +1,10 @@
|
|||
using Elsa.Abstractions;
|
||||
using Elsa.Extensions;
|
||||
using Elsa.Workflows.Management;
|
||||
using Elsa.Workflows.Models;
|
||||
using Elsa.Workflows.Runtime;
|
||||
using Elsa.Workflows.Runtime.Entities;
|
||||
using Elsa.Workflows.State;
|
||||
|
||||
namespace Elsa.Workflows.Api.Endpoints.Activities.TestRun;
|
||||
|
||||
|
|
@ -11,6 +15,7 @@ namespace Elsa.Workflows.Api.Endpoints.Activities.TestRun;
|
|||
internal class Endpoint(
|
||||
IWorkflowDefinitionService workflowDefinitionService,
|
||||
IActivityInvoker activityInvoker,
|
||||
IActivityExecutionMapper activityExecutionMapper,
|
||||
IIdentityGenerator identityGenerator,
|
||||
IServiceProvider serviceProvider)
|
||||
: ElsaEndpoint<Request>
|
||||
|
|
@ -45,7 +50,18 @@ internal class Endpoint(
|
|||
return;
|
||||
}
|
||||
|
||||
await activityInvoker.InvokeAsync(workflowExecutionContext, activity);
|
||||
var activityExecutionContext = await activityInvoker.InvokeAsync(workflowExecutionContext, activity);
|
||||
var record = activityExecutionMapper.Map(activityExecutionContext);
|
||||
var outcomes = record.Payload != null && record.Payload.TryGetValue("Outcomes", out var outcomesObj) ? outcomesObj as ICollection<string> : null;
|
||||
var response = new Response
|
||||
{
|
||||
Outputs = record.Outputs,
|
||||
Outcomes = outcomes,
|
||||
Exception = record.Exception,
|
||||
Status = record.Status
|
||||
};
|
||||
|
||||
await SendOkAsync(response, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,4 +69,12 @@ public class Request
|
|||
{
|
||||
public WorkflowDefinitionHandle WorkflowDefinitionHandle { get; set; } = null!;
|
||||
public ActivityHandle ActivityHandle { get; set; } = null!;
|
||||
}
|
||||
|
||||
public class Response
|
||||
{
|
||||
public IDictionary<string, object?>? Outputs { get; set; }
|
||||
public ICollection<string>? Outcomes { get; set; }
|
||||
public ExceptionState? Exception { get; set; }
|
||||
public ActivityStatus Status { get; set; }
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ public interface IActivityInvoker
|
|||
/// <param name="workflowExecutionContext">The workflow execution context.</param>
|
||||
/// <param name="activity">The activity to invoke.</param>
|
||||
/// <param name="options"></param>
|
||||
Task InvokeAsync(WorkflowExecutionContext workflowExecutionContext, IActivity activity, ActivityInvocationOptions? options = default);
|
||||
Task<ActivityExecutionContext> InvokeAsync(WorkflowExecutionContext workflowExecutionContext, IActivity activity, ActivityInvocationOptions? options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the specified activity execution context.
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ public class ActivityInvoker(
|
|||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task InvokeAsync(WorkflowExecutionContext workflowExecutionContext, IActivity activity, ActivityInvocationOptions? options = null)
|
||||
public async Task<ActivityExecutionContext> InvokeAsync(WorkflowExecutionContext workflowExecutionContext, IActivity activity, ActivityInvocationOptions? options = null)
|
||||
{
|
||||
// Setup an activity execution context, potentially reusing an existing one if requested.
|
||||
var existingActivityExecutionContext = options?.ExistingActivityExecutionContext;
|
||||
|
|
@ -34,6 +34,8 @@ public class ActivityInvoker(
|
|||
|
||||
// Execute the activity execution pipeline.
|
||||
await InvokeAsync(activityExecutionContext);
|
||||
|
||||
return activityExecutionContext;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
Loading…
Reference in a new issue