< Summary

Information
Class: Elsa.Workflows.Runtime.InterruptedLogExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/InterruptedLogExtensions.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 45
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
LogWorkflowInterruptedAsync()100%66100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/InterruptedLogExtensions.cs

#LineLine coverage
 1using Elsa.Workflows.Management.Entities;
 2using Elsa.Workflows.Runtime.Entities;
 3
 4namespace Elsa.Workflows.Runtime;
 5
 6/// <summary>
 7/// Helpers that record <c>WorkflowInterrupted</c> entries in the per-instance workflow execution log.
 8/// </summary>
 9public static class InterruptedLogExtensions
 10{
 11    /// <summary>
 12    /// Writes a <c>WorkflowInterrupted</c> entry for the supplied instance with the typed payload. The record's
 13    /// <c>Id</c> is generated via <paramref name="identityGenerator"/> so the format stays consistent with every
 14    /// other log record in the store. Activity-related fields are populated from <paramref name="payload"/>'s
 15    /// <see cref="WorkflowInterruptedPayload.LastActivityId"/> when available; otherwise they are left empty
 16    /// (the forensic record still uniquely identifies the interrupted instance via the workflow instance id).
 17    /// </summary>
 18    public static async Task LogWorkflowInterruptedAsync(
 19        this IWorkflowExecutionLogStore store,
 20        IIdentityGenerator identityGenerator,
 21        WorkflowInstance instance,
 22        WorkflowInterruptedPayload payload,
 23        CancellationToken cancellationToken = default)
 24    {
 325        var record = new WorkflowExecutionLogRecord
 326        {
 327            Id = identityGenerator.GenerateId(),
 328            WorkflowInstanceId = instance.Id,
 329            WorkflowDefinitionId = instance.DefinitionId,
 330            WorkflowDefinitionVersionId = instance.DefinitionVersionId,
 331            WorkflowVersion = instance.Version,
 332            ActivityInstanceId = payload.LastActivityId ?? string.Empty,
 333            ActivityId = payload.LastActivityId ?? string.Empty,
 334            ActivityType = string.Empty,
 335            ActivityNodeId = payload.LastActivityNodeId ?? string.Empty,
 336            Timestamp = payload.InterruptedAt,
 337            EventName = WorkflowInterruptedPayload.WorkflowInterruptedEventName,
 338            Source = "Elsa.Workflows.Runtime.GracefulShutdown",
 339            Message = $"Workflow execution cycle was force-cancelled by the runtime ({payload.Reason}).",
 340            Payload = payload,
 341        };
 42
 343        await store.AddAsync(record, cancellationToken);
 344    }
 45}

Methods/Properties

LogWorkflowInterruptedAsync()