From 5e2644f751a238502f264751b180904a67896309 Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Thu, 2 Jan 2025 11:43:21 +0100 Subject: [PATCH] Refactor workflow runtime structure and update handlers. Moved `CancelWorkflowsCommandHandler` to the shared runtime module. Updated related project references, features, and configurations accordingly. Improved `WorkflowInstance` actor to save state using `IWorkflowInstanceManager`. --- src/apps/Elsa.Server.Web/Program.cs | 2 +- .../Elsa.Workflows.Runtime.Distributed.csproj | 4 ++++ .../Features/DistributedRuntimeFeature.cs | 2 +- .../Actors/WorkflowInstance.cs | 2 ++ .../Features/DefaultWorkflowRuntimeFeature.cs | 13 +------------ .../Features/WorkflowRuntimeFeature.cs | 1 + .../Handlers/CancelWorkflowsCommandHandler.cs | 2 +- 7 files changed, 11 insertions(+), 15 deletions(-) rename src/modules/{Elsa.Workflows.Runtime.Distributed => Elsa.Workflows.Runtime}/Handlers/CancelWorkflowsCommandHandler.cs (92%) diff --git a/src/apps/Elsa.Server.Web/Program.cs b/src/apps/Elsa.Server.Web/Program.cs index 3e5a9b3f9..dd266fa03 100644 --- a/src/apps/Elsa.Server.Web/Program.cs +++ b/src/apps/Elsa.Server.Web/Program.cs @@ -74,7 +74,7 @@ const bool useAzureServiceBus = false; const bool useKafka = false; const bool useReadOnlyMode = false; const bool useSignalR = false; // Disabled until Elsa Studio sends authenticated requests. -const WorkflowRuntime workflowRuntime = WorkflowRuntime.Distributed; +const WorkflowRuntime workflowRuntime = WorkflowRuntime.ProtoActor; const DistributedCachingTransport distributedCachingTransport = DistributedCachingTransport.MassTransit; const MassTransitBroker massTransitBroker = MassTransitBroker.Memory; const bool useMultitenancy = false; diff --git a/src/modules/Elsa.Workflows.Runtime.Distributed/Elsa.Workflows.Runtime.Distributed.csproj b/src/modules/Elsa.Workflows.Runtime.Distributed/Elsa.Workflows.Runtime.Distributed.csproj index 870cd0d78..8f3983f11 100644 --- a/src/modules/Elsa.Workflows.Runtime.Distributed/Elsa.Workflows.Runtime.Distributed.csproj +++ b/src/modules/Elsa.Workflows.Runtime.Distributed/Elsa.Workflows.Runtime.Distributed.csproj @@ -18,4 +18,8 @@ + + + + diff --git a/src/modules/Elsa.Workflows.Runtime.Distributed/Features/DistributedRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime.Distributed/Features/DistributedRuntimeFeature.cs index 49a6526fe..0e05eca4a 100644 --- a/src/modules/Elsa.Workflows.Runtime.Distributed/Features/DistributedRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime.Distributed/Features/DistributedRuntimeFeature.cs @@ -2,8 +2,8 @@ using Elsa.Extensions; using Elsa.Features.Abstractions; using Elsa.Features.Attributes; using Elsa.Features.Services; -using Elsa.Workflows.Runtime.Distributed.Handlers; using Elsa.Workflows.Runtime.Features; +using Elsa.Workflows.Runtime.Handlers; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Workflows.Runtime.Distributed.Features; diff --git a/src/modules/Elsa.Workflows.Runtime.ProtoActor/Actors/WorkflowInstance.cs b/src/modules/Elsa.Workflows.Runtime.ProtoActor/Actors/WorkflowInstance.cs index b89314b12..7486c27b5 100644 --- a/src/modules/Elsa.Workflows.Runtime.ProtoActor/Actors/WorkflowInstance.cs +++ b/src/modules/Elsa.Workflows.Runtime.ProtoActor/Actors/WorkflowInstance.cs @@ -211,6 +211,8 @@ internal class WorkflowInstance( var workflowRunner = scope.ServiceProvider.GetRequiredService(); var workflowResult = await workflowRunner.RunAsync(WorkflowGraph, WorkflowState, runWorkflowOptions, _linkedCancellationToken); WorkflowState = workflowResult.WorkflowState; + var workflowInstanceManager = scope.ServiceProvider.GetRequiredService(); + await workflowInstanceManager.SaveAsync(WorkflowState, Context.CancellationToken); return workflowResult; } diff --git a/src/modules/Elsa.Workflows.Runtime/Features/DefaultWorkflowRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime/Features/DefaultWorkflowRuntimeFeature.cs index 41de318ac..6adf87b86 100644 --- a/src/modules/Elsa.Workflows.Runtime/Features/DefaultWorkflowRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime/Features/DefaultWorkflowRuntimeFeature.cs @@ -8,15 +8,4 @@ namespace Elsa.Workflows.Runtime.Features; /// Installs the default runtime services. /// [DependsOn(typeof(WorkflowRuntimeFeature))] -public class DefaultWorkflowRuntimeFeature : FeatureBase -{ - /// - public DefaultWorkflowRuntimeFeature(IModule module) : base(module) - { - } - - /// - public override void Apply() - { - } -} \ No newline at end of file +public class DefaultWorkflowRuntimeFeature(IModule module) : FeatureBase(module); \ No newline at end of file diff --git a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs index 91f0592b0..4ef109615 100644 --- a/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs +++ b/src/modules/Elsa.Workflows.Runtime/Features/WorkflowRuntimeFeature.cs @@ -310,6 +310,7 @@ public class WorkflowRuntimeFeature : FeatureBase // Domain handlers. .AddCommandHandler() + .AddCommandHandler() .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() diff --git a/src/modules/Elsa.Workflows.Runtime.Distributed/Handlers/CancelWorkflowsCommandHandler.cs b/src/modules/Elsa.Workflows.Runtime/Handlers/CancelWorkflowsCommandHandler.cs similarity index 92% rename from src/modules/Elsa.Workflows.Runtime.Distributed/Handlers/CancelWorkflowsCommandHandler.cs rename to src/modules/Elsa.Workflows.Runtime/Handlers/CancelWorkflowsCommandHandler.cs index 0f1f080bf..776db86c9 100644 --- a/src/modules/Elsa.Workflows.Runtime.Distributed/Handlers/CancelWorkflowsCommandHandler.cs +++ b/src/modules/Elsa.Workflows.Runtime/Handlers/CancelWorkflowsCommandHandler.cs @@ -2,7 +2,7 @@ using Elsa.Mediator.Contracts; using Elsa.Mediator.Models; using Elsa.Workflows.Runtime.Commands; -namespace Elsa.Workflows.Runtime.Distributed.Handlers; +namespace Elsa.Workflows.Runtime.Handlers; /// /// Handles the .