From 935d6987d552697331da8ba1c678d8d89756034c Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 13 Jun 2025 08:30:02 +0200 Subject: [PATCH] Commits workflow state during alteration (#6736) * Reduce default logging verbosity in appsettings.json * Commit workflow state during alteration execution Added `ICommitStateHandler` dependency and implemented workflow state commitment in `DefaultAlterationRunner` to ensure state persistence during alteration execution. --- src/apps/Elsa.Server.Web/appsettings.json | 6 ++---- .../Elsa.Alterations/Services/DefaultAlterationRunner.cs | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/apps/Elsa.Server.Web/appsettings.json b/src/apps/Elsa.Server.Web/appsettings.json index 2f6eccad2..39aa50c97 100644 --- a/src/apps/Elsa.Server.Web/appsettings.json +++ b/src/apps/Elsa.Server.Web/appsettings.json @@ -1,10 +1,8 @@ { "Logging": { "LogLevel": { - "Default": "Information", - "Microsoft.Hosting.Lifetime": "Information", - "Elsa": "Warning", - "Elsa.Workflows.Runtime.Middleware.Workflows.WorkflowHeartbeatMiddleware": "Warning" + "Default": "Warning", + "Microsoft.Hosting.Lifetime": "Information" } }, "HostBuilder": { diff --git a/src/modules/Elsa.Alterations/Services/DefaultAlterationRunner.cs b/src/modules/Elsa.Alterations/Services/DefaultAlterationRunner.cs index 71317a188..37ae0e87f 100644 --- a/src/modules/Elsa.Alterations/Services/DefaultAlterationRunner.cs +++ b/src/modules/Elsa.Alterations/Services/DefaultAlterationRunner.cs @@ -4,6 +4,7 @@ using Elsa.Alterations.Core.Results; using Elsa.Alterations.Middleware.Workflows; using Elsa.Common; using Elsa.Workflows; +using Elsa.Workflows.CommitStates; using Elsa.Workflows.Management; using Elsa.Workflows.Pipelines.WorkflowExecution; using Elsa.Workflows.Runtime; @@ -17,6 +18,7 @@ public class DefaultAlterationRunner( IWorkflowExecutionPipeline workflowExecutionPipeline, IWorkflowDefinitionService workflowDefinitionService, IWorkflowStateExtractor workflowStateExtractor, + ICommitStateHandler commitStateHandler, ISystemClock systemClock, IServiceProvider serviceProvider) : IAlterationRunner @@ -81,8 +83,13 @@ public class DefaultAlterationRunner( // Extract workflow state. workflowState = workflowStateExtractor.Extract(workflowExecutionContext); + + // Commit workflow state. + await commitStateHandler.CommitAsync(workflowExecutionContext, workflowState, cancellationToken); // Apply updated workflow state. + // TODO: Importing back into the workflow runtime makes sense, but this also causes another SAVE ction of the workflow instance in the DB, which also happens in the previous step during the commit action. + // Can we avoid this? Perhaps we need more granular control over when we purge and when we save to DB. await workflowClient.ImportStateAsync(workflowState, cancellationToken); // Check if the workflow has scheduled work.