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.
34 lines
1.9 KiB
C#
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();
|
|
}
|
|
} |