< 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
60%
Covered lines: 32
Uncovered lines: 21
Coverable lines: 53
Total lines: 100
Line coverage: 60.3%
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%210%
DispatchAsync()100%210%
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>
 47415public class BackgroundWorkflowDispatcher(ICommandSender commandSender, INotificationSender notificationSender, ITenantA
 16{
 17    /// <inheritdoc />
 18    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo
 19    {
 20        // Emit dispatching notification
 2421        await notificationSender.SendAsync(new WorkflowDefinitionDispatching(request), cancellationToken);
 22
 2423        var command = new DispatchWorkflowDefinitionCommand(request.DefinitionVersionId)
 2424        {
 2425            Input = request.Input,
 2426            Properties = request.Properties,
 2427            CorrelationId = request.CorrelationId,
 2428            InstanceId = request.InstanceId,
 2429            TriggerActivityId = request.TriggerActivityId,
 2430            ParentWorkflowInstanceId = request.ParentWorkflowInstanceId,
 2431            SchedulingActivityExecutionId = request.SchedulingActivityExecutionId,
 2432            SchedulingWorkflowInstanceId = request.SchedulingWorkflowInstanceId,
 2433            SchedulingCallStackDepth = request.SchedulingCallStackDepth
 2434        };
 35
 2436        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 2437        var response = DispatchWorkflowResponse.Success();
 38
 39        // Emit dispatched notification
 2440        await notificationSender.SendAsync(new WorkflowDefinitionDispatched(request, response), cancellationToken);
 41
 2442        return response;
 2443    }
 44
 45    /// <inheritdoc />
 46    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 47    {
 48        // Emit dispatching notification
 149        await notificationSender.SendAsync(new WorkflowInstanceDispatching(request), cancellationToken);
 50
 151        var command = new DispatchWorkflowInstanceCommand(request.InstanceId){
 152            BookmarkId = request.BookmarkId,
 153            ActivityHandle = request.ActivityHandle,
 154            Input = request.Input,
 155            Properties = request.Properties,
 156            CorrelationId = request.CorrelationId};
 57
 158        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 159        var response = DispatchWorkflowResponse.Success();
 60
 61        // Emit dispatched notification
 162        await notificationSender.SendAsync(new WorkflowInstanceDispatched(request, response), cancellationToken);
 63
 164        return response;
 165    }
 66
 67    /// <inheritdoc />
 68    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 69    {
 070        var command = new DispatchTriggerWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 071        {
 072            CorrelationId = request.CorrelationId,
 073            WorkflowInstanceId = request.WorkflowInstanceId,
 074            ActivityInstanceId = request.ActivityInstanceId,
 075            Input = request.Input,
 076            Properties = request.Properties
 077        };
 078        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 079        return DispatchWorkflowResponse.Success();
 080    }
 81
 82    /// <inheritdoc />
 83    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp
 84    {
 085        var command = new DispatchResumeWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 086        {
 087            CorrelationId = request.CorrelationId,
 088            WorkflowInstanceId = request.WorkflowInstanceId,
 089            ActivityInstanceId = request.ActivityInstanceId,
 090            Input = request.Input
 091        };
 092        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 093        return DispatchWorkflowResponse.Success();
 094    }
 95
 96    private IDictionary<object, object> CreateHeaders()
 97    {
 2598        return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
 99    }
 100}