< Summary

Information
Class: Elsa.Workflows.Runtime.BackgroundWorkflowDispatcher
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/BackgroundWorkflowDispatcher.cs
Line coverage
100%
Covered lines: 53
Uncovered lines: 0
Coverable lines: 53
Total lines: 106
Line coverage: 100%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
DispatchAsync()100%11100%
DispatchAsync()100%11100%
DispatchAsync()100%11100%
DispatchAsync()100%11100%
CreateHeaders()50%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Services/BackgroundWorkflowDispatcher.cs

#LineLine coverage
 1using Elsa.Common.Multitenancy;
 2using Elsa.Mediator;
 3using Elsa.Mediator.Contracts;
 4using Elsa.Tenants.Mediator;
 5using Elsa.Workflows.Runtime.Commands;
 6using Elsa.Workflows.Runtime.Notifications;
 7using Elsa.Workflows.Runtime.Requests;
 8using Elsa.Workflows.Runtime.Responses;
 9
 10namespace Elsa.Workflows.Runtime;
 11
 12/// <summary>
 13/// A simple implementation that queues the specified request for workflow execution on a non-durable background worker.
 14/// </summary>
 48515public class BackgroundWorkflowDispatcher(ICommandSender commandSender, INotificationSender notificationSender, ITenantA
 16{
 17    /// <inheritdoc />
 18    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo
 19    {
 20        // Emit dispatching notification
 2821        await notificationSender.SendAsync(new WorkflowDefinitionDispatching(request), cancellationToken);
 22
 2823        var command = new DispatchWorkflowDefinitionCommand(request.DefinitionVersionId)
 2824        {
 2825            Input = request.Input,
 2826            Properties = request.Properties,
 2827            CorrelationId = request.CorrelationId,
 2828            InstanceId = request.InstanceId,
 2829            TriggerActivityId = request.TriggerActivityId,
 2830            ParentWorkflowInstanceId = request.ParentWorkflowInstanceId,
 2831            SchedulingActivityExecutionId = request.SchedulingActivityExecutionId,
 2832            SchedulingWorkflowInstanceId = request.SchedulingWorkflowInstanceId,
 2833            SchedulingCallStackDepth = request.SchedulingCallStackDepth
 2834        };
 35
 36        // Background commands run independently of caller's lifecycle.
 2837        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 2838        var response = DispatchWorkflowResponse.Success();
 39
 40        // Emit dispatched notification
 2841        await notificationSender.SendAsync(new WorkflowDefinitionDispatched(request, response), cancellationToken);
 42
 2843        return response;
 2844    }
 45
 46    /// <inheritdoc />
 47    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 48    {
 49        // Emit dispatching notification
 250        await notificationSender.SendAsync(new WorkflowInstanceDispatching(request), cancellationToken);
 51
 252        var command = new DispatchWorkflowInstanceCommand(request.InstanceId){
 253            BookmarkId = request.BookmarkId,
 254            ActivityHandle = request.ActivityHandle,
 255            Input = request.Input,
 256            Properties = request.Properties,
 257            CorrelationId = request.CorrelationId};
 58
 59        // Background commands run independently of caller's lifecycle.
 260        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 261        var response = DispatchWorkflowResponse.Success();
 62
 63        // Emit dispatched notification
 264        await notificationSender.SendAsync(new WorkflowInstanceDispatched(request, response), cancellationToken);
 65
 266        return response;
 267    }
 68
 69    /// <inheritdoc />
 70    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 71    {
 172        var command = new DispatchTriggerWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 173        {
 174            CorrelationId = request.CorrelationId,
 175            WorkflowInstanceId = request.WorkflowInstanceId,
 176            ActivityInstanceId = request.ActivityInstanceId,
 177            Input = request.Input,
 178            Properties = request.Properties
 179        };
 80
 81        // Background commands run independently of caller's lifecycle.
 182        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 183        return DispatchWorkflowResponse.Success();
 184    }
 85
 86    /// <inheritdoc />
 87    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp
 88    {
 189        var command = new DispatchResumeWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 190        {
 191            CorrelationId = request.CorrelationId,
 192            WorkflowInstanceId = request.WorkflowInstanceId,
 193            ActivityInstanceId = request.ActivityInstanceId,
 194            Input = request.Input
 195        };
 96
 97        // Background commands run independently of caller's lifecycle.
 198        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 199        return DispatchWorkflowResponse.Success();
 1100    }
 101
 102    private IDictionary<object, object> CreateHeaders()
 103    {
 32104        return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
 105    }
 106}