< 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.
 273913        if (!context.NodeActivityLookup.ContainsKey(activityNode.Activity))
 014            throw new InvalidOperationException("The specified activity is not part of the workflow.");
 15
 273916        var scheduler = context.Scheduler;
 17
 273918        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
 273927        var activity = activityNode.Activity;
 273928        var tag = options?.Tag;
 273929        var workItem = new ActivityWorkItem(activity, owner, tag, options?.Variables, options?.ExistingActivityExecution
 273930        var completionCallback = options?.CompletionCallback;
 31
 273932        context.AddCompletionCallback(owner, activityNode, completionCallback, tag);
 273933        scheduler.Schedule(workItem);
 34
 273935        return workItem;
 36    }
 37}