< 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>
 47615public 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);
 2822        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 23
 24        // Background commands run independently of caller's lifecycle.
 2825        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 2826        var response = DispatchWorkflowResponse.Success();
 27
 28        // Emit dispatched notification
 2829        await notificationSender.SendAsync(new WorkflowDefinitionDispatched(request, response), cancellationToken);
 30
 2831        return response;
 2832    }
 33
 34    /// <inheritdoc />
 35    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchWorkflowInstanceRequest request, DispatchWorkflowO
 36    {
 37        // Emit dispatching notification
 238        await notificationSender.SendAsync(new WorkflowInstanceDispatching(request), cancellationToken);
 239        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 40
 41        // Background commands run independently of caller's lifecycle.
 242        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 243        var response = DispatchWorkflowResponse.Success();
 44
 45        // Emit dispatched notification
 246        await notificationSender.SendAsync(new WorkflowInstanceDispatched(request, response), cancellationToken);
 47
 248        return response;
 249    }
 50
 51    /// <inheritdoc />
 52    public async Task<DispatchWorkflowResponse> DispatchAsync(DispatchTriggerWorkflowsRequest request, DispatchWorkflowO
 53    {
 154        var command = WorkflowDispatchCommandFactory.CreateCommand(request);
 55
 56        // Background commands run independently of caller's lifecycle.
 157        await commandSender.SendAsync(command, CommandStrategy.Background, CreateHeaders(), CancellationToken.None);
 158        return DispatchWorkflowResponse.Success();
 159    }
 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    {
 3273        return TenantHeaders.CreateHeaders(tenantAccessor.Tenant?.Id);
 74    }
 75}