< 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.
 285413        if (!context.NodeActivityLookup.ContainsKey(activityNode.Activity))
 014            throw new InvalidOperationException("The specified activity is not part of the workflow.");
 15
 285416        var scheduler = context.Scheduler;
 17
 285418        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
 285427        var activity = activityNode.Activity;
 285428        var tag = options?.Tag;
 29
 30        // Use explicit SchedulingActivityExecutionId from options, or fall back to owner context.
 285431        var schedulingActivityExecutionId = options?.SchedulingActivityExecutionId ?? owner.Id;
 32
 33        // Use explicit SchedulingWorkflowInstanceId from options, if any.
 285434        var schedulingWorkflowInstanceId = options?.SchedulingWorkflowInstanceId;
 35
 285436        var workItem = new ActivityWorkItem(
 285437            activity,
 285438            owner,
 285439            tag,
 285440            options?.Variables,
 285441            options?.ExistingActivityExecutionContext,
 285442            options?.Input,
 285443            schedulingActivityExecutionId,
 285444            schedulingWorkflowInstanceId);
 285445        var completionCallback = options?.CompletionCallback;
 46
 285447        context.AddCompletionCallback(owner, activityNode, completionCallback, tag);
 285448        scheduler.Schedule(workItem);
 49
 285450        return workItem;
 51    }
 52}