< 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: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 75
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>
 51215public class BackgroundWorkflowDispatcher(ICommandSender commandSender, INotificationSender notificationSender, ITenantA
 16{
 17    /// <inheritdoc />
 18    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowDefinitionRequest request, DispatchWorkflo
 19    {
 20        // Emit dispatching notification
 3821        await notificationSender.SendAsync(new WorkflowDefinitionDispatching(request), cancellationToken);
 3822        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 23
 24        // Background commands run independently of caller's lifecycle.
 3825        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 3826        var response = DispatchWorkflowResponse.Success();
 27
 28        // Emit dispatched notification
 3829        await notificationSender.SendAsync(new WorkflowDefinitionDispatched(request, response), cancellationToken);
 30
 3831        return response;
 3832    }
 33
 34    /// <inheritdoc />
 35    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 36    {
 37        // Emit dispatching notification
 338        await notificationSender.SendAsync(new WorkflowInstanceDispatching(request), cancellationToken);
 339        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 40
 41        // Background commands run independently of caller's lifecycle.
 342        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 343        var response = DispatchWorkflowResponse.Success();
 44
 45        // Emit dispatched notification
 346        await notificationSender.SendAsync(new WorkflowInstanceDispatched(request, response), cancellationToken);
 47
 348        return response;
 349    }
 50
 51    /// <inheritdoc />
 52    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 53    {
 854        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 55
 56        // Background commands run independently of caller's lifecycle.
 857        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 858        return DispatchWorkflowResponse.Success();
 859    }
 60
 61    /// <inheritdoc />
 62    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchResumeWorkflowsRequest request, DispatchWorkflowOp
 63    {
 164        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 65
 66        // Background commands run independently of caller's lifecycle.
 167        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 168        return DispatchWorkflowResponse.Success();
 169    }
 70
 71    private IDictionary<object, object> CreateHeaders()
 72    {
 5073        return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
 74    }
 75}