< 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.
 281613        if (!context.NodeActivityLookup.ContainsKey(activityNode.Activity))
 014            throw new InvalidOperationException("The specified activity is not part of the workflow.");
 15
 281616        var scheduler = context.Scheduler;
 17
 281618        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
 281627        var activity = activityNode.Activity;
 281628        var tag = options?.Tag;
 29
 30        // Use explicit SchedulingActivityExecutionId from options, or fall back to owner context.
 281631        var schedulingActivityExecutionId = options?.SchedulingActivityExecutionId ?? owner.Id;
 32
 33        // Use explicit SchedulingWorkflowInstanceId from options, if any.
 281634        var schedulingWorkflowInstanceId = options?.SchedulingWorkflowInstanceId;
 35
 281636        var workItem = new ActivityWorkItem(
 281637            activity,
 281638            owner,
 281639            tag,
 281640            options?.Variables,
 281641            options?.ExistingActivityExecutionContext,
 281642            options?.Input,
 281643            schedulingActivityExecutionId,
 281644            schedulingWorkflowInstanceId);
 281645        var completionCallback = options?.CompletionCallback;
 46
 281647        context.AddCompletionCallback(owner, activityNode, completionCallback, tag);
 281648        scheduler.Schedule(workItem);
 49
 281650        return workItem;
 51    }
 52}