< Summary

Information
Class: Elsa.Workflows.Runtime.DefaultCommitStateHandler
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultCommitStateHandler.cs
Line coverage
92%
Covered lines: 36
Uncovered lines: 3
Coverable lines: 39
Total lines: 66
Line coverage: 92.3%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
CommitAsync()100%210%
CommitAsync()100%22100%
<CommitAsync()100%11100%
ClearActivityExecutionContextTaint(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/DefaultCommitStateHandler.cs

#LineLine coverage
 1using System.Runtime.ExceptionServices;
 2using Elsa.Mediator.Contracts;
 3using Elsa.Workflows.CommitStates;
 4using Elsa.Workflows.Management;
 5using Elsa.Workflows.Management.Entities;
 6using Elsa.Workflows.Runtime.Entities;
 7using Elsa.Workflows.Runtime.Notifications;
 8using Elsa.Workflows.Runtime.Requests;
 9using Elsa.Workflows.State;
 10
 11namespace Elsa.Workflows.Runtime;
 12
 53913public class DefaultCommitStateHandler(
 53914    IWorkflowInstanceManager workflowInstanceManager,
 53915    IBookmarksPersister bookmarkPersister,
 53916    IVariablePersistenceManager variablePersistenceManager,
 53917    IWorkflowCommitTransaction workflowCommitTransaction,
 53918    IWorkflowCommitNotificationBuffer workflowCommitNotificationBuffer,
 53919    INotificationSender notificationSender,
 53920    ILogRecordSink<ActivityExecutionRecord> activityExecutionLogRecordSink,
 53921    ILogRecordSink<WorkflowExecutionLogRecord> workflowExecutionLogRecordSink) : ICommitStateHandler
 22{
 23    public async Task CommitAsync(WorkflowExecutionContext workflowExecutionContext, CancellationToken cancellationToken
 24    {
 025        var workflowState = workflowInstanceManager.ExtractWorkflowState(workflowExecutionContext);
 026        await CommitAsync(workflowExecutionContext, workflowState, cancellationToken);
 027    }
 28
 29    public async Task CommitAsync(WorkflowExecutionContext workflowExecutionContext, WorkflowState workflowState, Cancel
 30    {
 57031        WorkflowInstance? workflowInstance = null;
 57032        using var notificationScope = workflowCommitNotificationBuffer.Begin();
 57033        await workflowCommitTransaction.ExecuteAsync(async ct =>
 57034        {
 57035            var updateBookmarksRequest = new UpdateBookmarksRequest(workflowExecutionContext, workflowExecutionContext.B
 57036            await bookmarkPersister.PersistBookmarksAsync(updateBookmarksRequest);
 57037            await activityExecutionLogRecordSink.PersistExecutionLogsAsync(workflowExecutionContext, ct);
 57038            await workflowExecutionLogRecordSink.PersistExecutionLogsAsync(workflowExecutionContext, ct);
 57039            await variablePersistenceManager.SaveVariablesAsync(workflowExecutionContext);
 57040            workflowInstance = await workflowInstanceManager.SaveAsync(workflowState, ct);
 113941        }, cancellationToken);
 42
 56943        ClearActivityExecutionContextTaint(workflowExecutionContext);
 56944        workflowExecutionContext.ExecutionLog.Clear();
 56945        workflowExecutionContext.ClearCompletedActivityExecutionContexts();
 56946        ExceptionDispatchInfo? flushException = null;
 47        try
 48        {
 56949            await notificationScope.FlushAsync(cancellationToken);
 56850        }
 151        catch (Exception ex) when (ex is not OperationCanceledException and not OutOfMemoryException)
 52        {
 153            flushException = ExceptionDispatchInfo.Capture(ex);
 154        }
 55
 56956        await workflowExecutionContext.ExecuteDeferredTasksAsync();
 56957        await notificationSender.SendAsync(new WorkflowStateCommitted(workflowExecutionContext, workflowState, workflowI
 56958        flushException?.Throw();
 56859    }
 60
 61    private static void ClearActivityExecutionContextTaint(WorkflowExecutionContext workflowExecutionContext)
 62    {
 1402663        foreach (var activityExecutionContext in workflowExecutionContext.ActivityExecutionContexts.Where(x => x.IsDirty
 429664            activityExecutionContext.ClearTaint();
 56965    }
 66}