-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ExecuteWorkflow activity (#6134)
* Add ExecuteWorkflow activity and enable multitenancy Introduced the ExecuteWorkflow activity to create and execute workflow instances, and updated runtime settings to use ProtoActor for distributed caching transport. Enabled multitenancy for the Elsa Server Web application. * Namespace renames (#6135) * Create ExecuteWorkflows tests and workflows Add unit tests for executing workflows, including MainWorkflow and SubroutineWorkflow. Also, rename ExecutedWorkflowResult to ExecuteWorkflowResult in the runtime module for consistency. * Add output definitions to WorkflowBuilder Refactored the `WithInput` method for clarity and added multiple `WithOutput` methods to support different ways of defining workflow outputs. These changes enhance the flexibility and readability of the workflow configuration process by providing a consistent API for input and output definitions. * Refactor namespaces in component tests Updated namespaces from Helpers to specific contexts like Fixtures, Abstractions, Consumers, Decorators, etc., to improve code organization and readability. This change affects multiple files across different test scenarios and modules. * Disable RabbitMQ and multitenancy, rename test class Commented out RabbitMQ usage in WorkflowServer.cs to focus on other transports. Changed multitenancy flag to false in Program.cs. Renamed DispatchWorkflowsTests to ExecuteWorkflowsTests for clarity.
- Loading branch information
1 parent
49a7f22
commit 1ed6695
Showing
37 changed files
with
324 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/modules/Elsa.Workflows.Runtime/Activities/ExecuteWorkflow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Runtime.CompilerServices; | ||
using Elsa.Common.Models; | ||
using Elsa.Extensions; | ||
using Elsa.Workflows.Attributes; | ||
using Elsa.Workflows.Management; | ||
using Elsa.Workflows.Models; | ||
using Elsa.Workflows.Options; | ||
using Elsa.Workflows.UIHints; | ||
using JetBrains.Annotations; | ||
|
||
namespace Elsa.Workflows.Runtime.Activities; | ||
|
||
/// <summary> | ||
/// Creates a new workflow instance of the specified workflow and dispatches it for execution. | ||
/// </summary> | ||
[Activity("Elsa", "Composition", "Create a new workflow instance of the specified workflow and execute it.", Kind = ActivityKind.Task)] | ||
[UsedImplicitly] | ||
public class ExecuteWorkflow : Activity<ExecuteWorkflowResult> | ||
{ | ||
/// <inheritdoc /> | ||
public ExecuteWorkflow([CallerFilePath] string? source = default, [CallerLineNumber] int? line = default) : base(source, line) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// The definition ID of the workflow to execute. | ||
/// </summary> | ||
[Input( | ||
DisplayName = "Workflow Definition", | ||
Description = "The definition ID of the workflow to execute.", | ||
UIHint = InputUIHints.WorkflowDefinitionPicker | ||
)] | ||
public Input<string> WorkflowDefinitionId { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// The correlation ID to associate the workflow with. | ||
/// </summary> | ||
[Input( | ||
DisplayName = "Correlation ID", | ||
Description = "The correlation ID to associate the workflow with." | ||
)] | ||
public Input<string?> CorrelationId { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// The input to send to the workflow. | ||
/// </summary> | ||
[Input(Description = "The input to send to the workflow.")] | ||
public Input<IDictionary<string, object>?> Input { get; set; } = default!; | ||
|
||
/// <inheritdoc /> | ||
protected override async ValueTask ExecuteAsync(ActivityExecutionContext context) | ||
{ | ||
var result = await ExecuteWorkflowAsync(context); | ||
context.SetResult(result); | ||
await context.CompleteActivityAsync(); | ||
} | ||
|
||
private async ValueTask<ExecuteWorkflowResult> ExecuteWorkflowAsync(ActivityExecutionContext context) | ||
{ | ||
var workflowDefinitionId = WorkflowDefinitionId.Get(context); | ||
var input = Input.GetOrDefault(context) ?? new Dictionary<string, object>(); | ||
var correlationId = CorrelationId.GetOrDefault(context); | ||
var workflowInvoker = context.GetRequiredService<IWorkflowInvoker>(); | ||
var identityGenerator = context.GetRequiredService<IIdentityGenerator>(); | ||
var workflowDefinitionService = context.GetRequiredService<IWorkflowDefinitionService>(); | ||
var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(workflowDefinitionId, VersionOptions.Published, context.CancellationToken); | ||
|
||
if (workflowGraph == null) | ||
throw new Exception($"No published version of workflow definition with ID {workflowDefinitionId} found."); | ||
|
||
var options = new RunWorkflowOptions | ||
{ | ||
ParentWorkflowInstanceId = context.WorkflowExecutionContext.Id, | ||
Input = input, | ||
CorrelationId = correlationId, | ||
WorkflowInstanceId = identityGenerator.GenerateId() | ||
}; | ||
|
||
var workflowResult = await workflowInvoker.InvokeAsync(workflowGraph, options, context.CancellationToken); | ||
var info = new ExecuteWorkflowResult | ||
{ | ||
WorkflowInstanceId = options.WorkflowInstanceId, | ||
Status = workflowResult.WorkflowState.Status, | ||
SubStatus = workflowResult.WorkflowState.SubStatus, | ||
Output = workflowResult.WorkflowState.Output | ||
}; | ||
|
||
return info; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/modules/Elsa.Workflows.Runtime/Models/ExecuteWorkflowResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace Elsa.Workflows.Runtime; | ||
|
||
/// <summary> | ||
/// Represents the result of executing a workflow. | ||
/// </summary> | ||
public class ExecuteWorkflowResult | ||
{ | ||
public string WorkflowDefinitionVersionId { get; set; } = default!; | ||
public string WorkflowInstanceId { get; set; } = default!; | ||
public string? CorrelationId { get; set; } | ||
public WorkflowStatus Status { get; set; } | ||
public WorkflowSubStatus SubStatus { get; set; } | ||
public IDictionary<string, object>? Output { get; set; } | ||
} |
3 changes: 2 additions & 1 deletion
3
test/component/Elsa.Workflows.ComponentTests/Helpers/Abstractions/AppComponentTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/App.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/AppCollection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/Cluster.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
test/component/Elsa.Workflows.ComponentTests/Helpers/Fixtures/Infrastructure.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...component/Elsa.Workflows.ComponentTests/Helpers/Materializers/TestWorkflowMaterializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...component/Elsa.Workflows.ComponentTests/Helpers/WorkflowProviders/TestWorkflowProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
test/component/Elsa.Workflows.ComponentTests/Scenarios/Activities/FlowJoins/Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...sa.Workflows.ComponentTests/Scenarios/BulkDispatchWorkflows/BulkDispatchWorkflowsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ntTests/Scenarios/CachingAndWorkflowDefinitionActivity/WorkflowDefinitionActivityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...ent/Elsa.Workflows.ComponentTests/Scenarios/ClusteredHosting/ActivityRegistrySyncTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...onent/Elsa.Workflows.ComponentTests/Scenarios/DispatchWorkflows/DispatchWorkflowsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.