< Summary

Information
Class: Elsa.Workflows.WorkflowExecutionContextSchedulerStrategy
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/WorkflowExecutionContextSchedulerStrategy.cs
Line coverage
83%
Covered lines: 20
Uncovered lines: 4
Coverable lines: 24
Total lines: 52
Line coverage: 83.3%
Branch coverage
80%
Covered branches: 21
Total branches: 26
Branch coverage: 80.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Schedule(...)80.76%292683.33%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Services/WorkflowExecutionContextSchedulerStrategy.cs

#LineLine coverage
 1using Elsa.Workflows.Models;
 2using Elsa.Workflows.Options;
 3
 4namespace Elsa.Workflows;
 5
 6/// <inheritdoc />
 7public class WorkflowExecutionContextSchedulerStrategy : IWorkflowExecutionContextSchedulerStrategy
 8{
 9    /// <inheritdoc />
 10    public ActivityWorkItem Schedule(WorkflowExecutionContext context, ActivityNode activityNode, ActivityExecutionConte
 11    {
 12        // Validate that the specified activity is part of the workflow.
 292413        if (!context.NodeActivityLookup.ContainsKey(activityNode.Activity))
 014            throw new InvalidOperationException("The specified activity is not part of the workflow.");
 15
 292416        var scheduler = context.Scheduler;
 17
 292418        if (options?.PreventDuplicateScheduling == true)
 19        {
 20            // Check if the activity is already scheduled for the specified owner.
 021            var existingWorkItem = scheduler.Find(x => x.Activity.NodeId == activityNode.NodeId && x.Owner == owner);
 22
 023            if (existingWorkItem != null)
 024                return existingWorkItem;
 25        }
 26
 292427        var activity = activityNode.Activity;
 292428        var tag = options?.Tag;
 29
 30        // Use explicit SchedulingActivityExecutionId from options, or fall back to owner context.
 292431        var schedulingActivityExecutionId = options?.SchedulingActivityExecutionId ?? owner.Id;
 32
 33        // Use explicit SchedulingWorkflowInstanceId from options, if any.
 292434        var schedulingWorkflowInstanceId = options?.SchedulingWorkflowInstanceId;
 35
 292436        var workItem = new ActivityWorkItem(
 292437            activity,
 292438            owner,
 292439            tag,
 292440            options?.Variables,
 292441            options?.ExistingActivityExecutionContext,
 292442            options?.Input,
 292443            schedulingActivityExecutionId,
 292444            schedulingWorkflowInstanceId);
 292445        var completionCallback = options?.CompletionCallback;
 46
 292447        context.AddCompletionCallback(owner, activityNode, completionCallback, tag);
 292448        scheduler.Schedule(workItem);
 49
 292450        return workItem;
 51    }
 52}