< 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
71%
Covered lines: 10
Uncovered lines: 4
Coverable lines: 14
Total lines: 37
Line coverage: 71.4%
Branch coverage
75%
Covered branches: 15
Total branches: 20
Branch coverage: 75%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Schedule(...)75%292071.42%

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.
 258313        if (!context.NodeActivityLookup.ContainsKey(activityNode.Activity))
 014            throw new InvalidOperationException("The specified activity is not part of the workflow.");
 15
 258316        var scheduler = context.Scheduler;
 17
 258318        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
 258327        var activity = activityNode.Activity;
 258328        var tag = options?.Tag;
 258329        var workItem = new ActivityWorkItem(activity, owner, tag, options?.Variables, options?.ExistingActivityExecution
 258330        var completionCallback = options?.CompletionCallback;
 31
 258332        context.AddCompletionCallback(owner, activityNode, completionCallback, tag);
 258333        scheduler.Schedule(workItem);
 34
 258335        return workItem;
 36    }
 37}