0_Program.cs
1_CommitStateHandler.cs
This file contains hidden or 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
| var services = new ServiceCollection(); | |
| services.AddScoped<CommitStateHandler>(); | |
| services.AddElsa(elsa => | |
| { | |
| elsa.UseWorkflows(workflows => | |
| { | |
| workflows.CommitStateHandler = sp => sp.GetRequiredService<CommitStateHandler>(); | |
| workflows.WithWorkflowExecutionPipeline(pipeline => pipeline | |
| .Reset() | |
| .UseEngineExceptionHandling() | |
| .UseExceptionHandling() | |
| .UseDefaultActivityScheduler()); | |
| }); | |
| elsa.UseWorkflowRuntime(runtime => | |
| { | |
| runtime.DistributedLockProvider = _ => new FileDistributedSynchronizationProvider( | |
| new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString(), "App_Data", "locks"))); | |
| }); | |
| }); |
This file contains hidden or 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
| public class CommitStateHandler( | |
| 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(); | |
| } | |
| } |