< 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
58%
Covered lines: 29
Uncovered lines: 21
Coverable lines: 50
Total lines: 97
Line coverage: 58%
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>
 44115public 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        };
 32
 2433        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 2434        var response = DispatchWorkflowResponse.Success();
 35
 36        // Emit dispatched notification
 2437        await notificationSender.SendAsync(new WorkflowDefinitionDispatched(request, response), cancellationToken);
 38
 2439        return response;
 2440    }
 41
 42    /// <inheritdoc />
 43    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 44    {
 45        // Emit dispatching notification
 146        await notificationSender.SendAsync(new WorkflowInstanceDispatching(request), cancellationToken);
 47
 148        var command = new DispatchWorkflowInstanceCommand(request.InstanceId){
 149            BookmarkId = request.BookmarkId,
 150            ActivityHandle = request.ActivityHandle,
 151            Input = request.Input,
 152            Properties = request.Properties,
 153            CorrelationId = request.CorrelationId};
 54
 155        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 156        var response = DispatchWorkflowResponse.Success();
 57
 58        // Emit dispatched notification
 159        await notificationSender.SendAsync(new WorkflowInstanceDispatched(request, response), cancellationToken);
 60
 161        return response;
 162    }
 63
 64    /// <inheritdoc />
 65    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 66    {
 067        var command = new DispatchTriggerWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 068        {
 069            CorrelationId = request.CorrelationId,
 070            WorkflowInstanceId = request.WorkflowInstanceId,
 071            ActivityInstanceId = request.ActivityInstanceId,
 072            Input = request.Input,
 073            Properties = request.Properties
 074        };
 075        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 076        return DispatchWorkflowResponse.Success();
 077    }
 78
 79    /// <inheritdoc />
 80    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp
 81    {
 082        var command = new DispatchResumeWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 083        {
 084            CorrelationId = request.CorrelationId,
 085            WorkflowInstanceId = request.WorkflowInstanceId,
 086            ActivityInstanceId = request.ActivityInstanceId,
 087            Input = request.Input
 088        };
 089        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 090        return DispatchWorkflowResponse.Success();
 091    }
 92
 93    private IDictionary<object, object> CreateHeaders()
 94    {
 2595        return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
 96    }
 97}