Last active
June 22, 2025 06:42
-
-
Save badsyntax/8689341bd75e5688d06b875c6dc9bdbb to your computer and use it in GitHub Desktop.
Elsa 3.4.0 configuration for running short lived workflows that don't require any persistence
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment