| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Workflows.Runtime; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Api.Endpoints.WorkflowInstances.BulkCancel; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents an endpoint for bulk cancelling workflow instances. |
| | | 9 | | /// </summary> |
| | | 10 | | [PublicAPI] |
| | 1 | 11 | | public class BulkCancel(IWorkflowCancellationService workflowCancellationService) : ElsaEndpoint<Request, Response> |
| | | 12 | | { |
| | | 13 | | /// <inheritdoc /> |
| | | 14 | | public override void Configure() |
| | | 15 | | { |
| | 1 | 16 | | Post("/bulk-actions/cancel/workflow-instances/"); |
| | 1 | 17 | | ConfigurePermissions("cancel:workflow-instances"); |
| | 1 | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <inheritdoc /> |
| | | 21 | | public override async Task<Response> ExecuteAsync(Request request, CancellationToken cancellationToken) |
| | | 22 | | { |
| | 0 | 23 | | var tasks = new List<Task<int>>(); |
| | | 24 | | |
| | 0 | 25 | | if (request.Ids is not null) |
| | 0 | 26 | | tasks.Add(workflowCancellationService.CancelWorkflowsAsync(request.Ids!, cancellationToken)); |
| | 0 | 27 | | if (request.DefinitionVersionId is not null) |
| | 0 | 28 | | tasks.Add(workflowCancellationService.CancelWorkflowByDefinitionVersionAsync(request.DefinitionVersionId!, c |
| | 0 | 29 | | if (request.DefinitionId is not null) |
| | 0 | 30 | | tasks.Add(workflowCancellationService.CancelWorkflowByDefinitionAsync(request.DefinitionId!, request.Version |
| | | 31 | | |
| | 0 | 32 | | await Task.WhenAll(tasks); |
| | | 33 | | |
| | 0 | 34 | | return new(tasks.Sum(t => t.Result)); |
| | 0 | 35 | | } |
| | | 36 | | } |