elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultCommitStateHandler.cs
Sipke Schoorstra ce859efc4a Refactor commit state handling with a strategy-based approach
Replaced the legacy commit state behavior enums and options with a flexible, strategy-based system for activities and workflows. Introduced new interfaces, models, and strategies to enable fine-grained control of commit state logic. Updated related code to integrate the new commit strategies, ensuring modular and extensible commit handling.
2025-01-30 11:59:47 +01:00

34 lines
1.9 KiB
C#

using Elsa.Workflows.CommitStates;
using Elsa.Workflows.Management;
using Elsa.Workflows.Runtime.Entities;
using Elsa.Workflows.Runtime.Requests;
using Elsa.Workflows.State;
namespace Elsa.Workflows.Runtime;
public class DefaultCommitStateHandler(
IWorkflowInstanceManager workflowInstanceManager,
IBookmarksPersister bookmarkPersister,
IVariablePersistenceManager variablePersistenceManager,
ILogRecordSink<ActivityExecutionRecord> activityExecutionLogRecordSink,
ILogRecordSink<WorkflowExecutionLogRecord> workflowExecutionLogRecordSink) : ICommitStateHandler
{
public async Task CommitAsync(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken = default)
{
var workflowState = workflowInstanceManager.ExtractWorkflowState(workflowExecutionContext);
await CommitAsync(workflowExecutionContext, workflowState, cancellationToken);
}
public async Task CommitAsync(WorkflowExecutionContext workflowExecutionContext, WorkflowState workflowState, CancellationToken cancellationToken = default)
{
var updateBookmarksRequest = new UpdateBookmarksRequest(workflowExecutionContext, workflowExecutionContext.BookmarksDiff, workflowExecutionContext.CorrelationId);
await bookmarkPersister.PersistBookmarksAsync(updateBookmarksRequest);
await activityExecutionLogRecordSink.PersistExecutionLogsAsync(workflowExecutionContext, cancellationToken);
await workflowExecutionLogRecordSink.PersistExecutionLogsAsync(workflowExecutionContext, cancellationToken);
await variablePersistenceManager.SaveVariablesAsync(workflowExecutionContext);
await workflowInstanceManager.SaveAsync(workflowState, cancellationToken);
workflowExecutionContext.ExecutionLog.Clear();
workflowExecutionContext.ClearCompletedActivityExecutionContexts();
await workflowExecutionContext.ExecuteDeferredTasksAsync();
}
}