Quantcast
Channel: Recent Gists from badsyntax
Viewing all articles
Browse latest Browse all 37

Elsa 3.4.0 configuration for running short lived workflows that don't require any persistence

$
0
0
0_Program.cs
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")));
});
});
1_CommitStateHandler.cs
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();
}
}

Viewing all articles
Browse latest Browse all 37

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>