< Summary

Information
Class: Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.BulkDispatch.Endpoint
Assembly: Elsa.Workflows.Api
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/BulkDispatch/Endpoint.cs
Line coverage
15%
Covered lines: 4
Uncovered lines: 22
Coverable lines: 26
Total lines: 53
Line coverage: 15.3%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
Configure()100%11100%
HandleAsync()0%4260%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Api/Endpoints/WorkflowDefinitions/BulkDispatch/Endpoint.cs

#LineLine coverage
 1using Elsa.Abstractions;
 2using Elsa.Common.Models;
 3using Elsa.Workflows.Management;
 4using Elsa.Workflows.Runtime;
 5using Elsa.Workflows.Runtime.Contracts;
 6using Elsa.Workflows.Runtime.Requests;
 7using JetBrains.Annotations;
 8
 9namespace Elsa.Workflows.Api.Endpoints.WorkflowDefinitions.BulkDispatch;
 10
 11[PublicAPI]
 112internal class Endpoint(IWorkflowDefinitionService workflowDefinitionService, IWorkflowDispatcher workflowDispatcher, II
 13    : ElsaEndpoint<Request, Response>
 14{
 15    public override void Configure()
 16    {
 117        Post("/workflow-definitions/{definitionId}/bulk-dispatch");
 118        ConfigurePermissions("exec:workflow-definitions");
 119    }
 20
 21    public override async Task HandleAsync(Request request, CancellationToken cancellationToken)
 22    {
 023        var definitionId = request.DefinitionId;
 024        var versionOptions = request.VersionOptions ?? VersionOptions.Published;
 025        var workflowGraph = await workflowDefinitionService.FindWorkflowGraphAsync(definitionId, versionOptions, cancell
 26
 027        if (workflowGraph == null)
 28        {
 029            await Send.NotFoundAsync(cancellationToken);
 030            return;
 31        }
 32
 033        var instanceIds = new List<string>();
 34
 035        for (var i = 0; i < request.Count; i++)
 36        {
 037            var instanceId = identityGenerator.GenerateId();
 038            var triggerActivityId = request.TriggerActivityId;
 039            var input = (IDictionary<string, object>?)request.Input;
 040            var dispatchRequest = new DispatchWorkflowDefinitionRequest(workflowGraph.Workflow.Identity.Id)
 041            {
 042                Input = input,
 043                InstanceId = instanceId,
 044                TriggerActivityId = triggerActivityId
 045            };
 46
 047            await workflowDispatcher.DispatchAsync(dispatchRequest, cancellationToken: cancellationToken);
 048            instanceIds.Add(instanceId);
 049        }
 50
 051        await Send.OkAsync(new Response(instanceIds), cancellationToken);
 052    }
 53}