< Summary

Information
Class: Elsa.Bpmn.Hosting.BpmnWorkTeardown
Assembly: Elsa.Bpmn
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn/Hosting/BpmnWorkTeardown.cs
Line coverage
100%
Covered lines: 4
Uncovered lines: 0
Coverable lines: 4
Total lines: 34
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FindContext(...)100%11100%
CancelSubtreeAsync()100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Bpmn/Hosting/BpmnWorkTeardown.cs

#LineLine coverage
 1using Elsa.Extensions;
 2using Elsa.Workflows;
 3
 4namespace Elsa.Bpmn.Hosting;
 5
 6/// <summary>
 7/// Stops a unit of work and everything it in turn started.
 8/// </summary>
 9/// <remarks>
 10/// Both places that tear work down go through here: the interpreter's <c>CancelWorkSubtree</c> command, and a scope
 11/// terminalizing the unit of work whose fault it just claimed. The mechanism is the same in either case.
 12/// </remarks>
 13internal static class BpmnWorkTeardown
 14{
 15    /// <summary>The activity execution with the given id, or <c>null</c> when it has already gone.</summary>
 16    public static ActivityExecutionContext? FindContext(WorkflowExecutionContext workflowExecutionContext, string activi
 4317        workflowExecutionContext.ActivityExecutionContexts.FirstOrDefault(x => string.Equals(x.Id, activityExecutionCont
 18
 19    /// <summary>
 20    /// Tears down a unit of work and everything underneath it.
 21    /// </summary>
 22    /// <remarks>
 23    /// Cancellation itself needs no BPMN-specific code: the public <c>CancelActivityAsync</c> extension walks the
 24    /// child subtree recursively, which is exactly what "and everything it in turn started" means, and it withdraws
 25    /// the scheduled-but-not-yet-invoked work items in that subtree so nothing from the destroyed branch runs
 26    /// afterwards. The only thing this method adds is the reason, recorded on the torn-down activity's journal
 27    /// before it goes, so the workflow's execution log says which BPMN element destroyed the branch and why.
 28    /// </remarks>
 29    public static async ValueTask CancelSubtreeAsync(ActivityExecutionContext childContext, string reason)
 30    {
 1731        childContext.AddExecutionLogEntry("Torn down by BPMN", reason);
 1732        await childContext.CancelActivityAsync();
 1733    }
 34}