< 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
31%
Covered lines: 14
Uncovered lines: 30
Coverable lines: 44
Total lines: 80
Line coverage: 31.8%
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%210%
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.Requests;
 7using Elsa.Workflows.Runtime.Responses;
 8
 9namespace Elsa.Workflows.Runtime;
 10
 11/// <summary>
 12/// A simple implementation that queues the specified request for workflow execution on a non-durable background worker.
 13/// </summary>
 32914public class BackgroundWorkflowDispatcher(ICommandSender commandSender, ITenantAccessor tenantAccessor) : IWorkflowDispa
 15{
 16    /// <inheritdoc />
 17    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo
 18    {
 2319        var command = new DispatchWorkflowDefinitionCommand(request.DefinitionVersionId)
 2320        {
 2321            Input = request.Input,
 2322            Properties = request.Properties,
 2323            CorrelationId = request.CorrelationId,
 2324            InstanceId = request.InstanceId,
 2325            TriggerActivityId = request.TriggerActivityId,
 2326            ParentWorkflowInstanceId = request.ParentWorkflowInstanceId,
 2327        };
 28
 2329        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 2330        return DispatchWorkflowResponse.Success();
 2331    }
 32
 33    /// <inheritdoc />
 34    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 35    {
 036        var command = new DispatchWorkflowInstanceCommand(request.InstanceId){
 037            BookmarkId = request.BookmarkId,
 038            ActivityHandle = request.ActivityHandle,
 039            Input = request.Input,
 040            Properties = request.Properties,
 041            CorrelationId = request.CorrelationId};
 42
 043        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 044        return DispatchWorkflowResponse.Success();
 045    }
 46
 47    /// <inheritdoc />
 48    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 49    {
 050        var command = new DispatchTriggerWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 051        {
 052            CorrelationId = request.CorrelationId,
 053            WorkflowInstanceId = request.WorkflowInstanceId,
 054            ActivityInstanceId = request.ActivityInstanceId,
 055            Input = request.Input,
 056            Properties = request.Properties
 057        };
 058        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 059        return DispatchWorkflowResponse.Success();
 060    }
 61
 62    /// <inheritdoc />
 63    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp
 64    {
 065        var command = new DispatchResumeWorkflowsCommand(request.ActivityTypeName, request.BookmarkPayload)
 066        {
 067            CorrelationId = request.CorrelationId,
 068            WorkflowInstanceId = request.WorkflowInstanceId,
 069            ActivityInstanceId = request.ActivityInstanceId,
 070            Input = request.Input
 071        };
 072        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), cancellationToken);
 073        return DispatchWorkflowResponse.Success();
 074    }
 75
 76    private IDictionary<object, object> CreateHeaders()
 77    {
 2378        return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
 79    }
 80}