| | | 1 | | using Elsa.Abstractions; |
| | | 2 | | using Elsa.Alterations.Core.Contracts; |
| | | 3 | | using JetBrains.Annotations; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Alterations.Endpoints.Alterations.Run; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Executes an alteration plan by targeting workflow instances by ID. |
| | | 9 | | /// </summary> |
| | | 10 | | [PublicAPI] |
| | | 11 | | public class Run : ElsaEndpoint<Request, Response> |
| | | 12 | | { |
| | | 13 | | private readonly IAlterationRunner _alterationRunner; |
| | | 14 | | private readonly IAlteredWorkflowDispatcher _workflowDispatcher; |
| | | 15 | | |
| | | 16 | | /// <inheritdoc /> |
| | 1 | 17 | | public Run(IAlterationRunner alterationRunner, IAlteredWorkflowDispatcher workflowDispatcher) |
| | | 18 | | { |
| | 1 | 19 | | _alterationRunner = alterationRunner; |
| | 1 | 20 | | _workflowDispatcher = workflowDispatcher; |
| | 1 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public override void Configure() |
| | | 25 | | { |
| | 1 | 26 | | Post("/alterations/run"); |
| | 1 | 27 | | ConfigurePermissions("run:alterations"); |
| | 1 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <inheritdoc /> |
| | | 31 | | public override async Task HandleAsync(Request request, CancellationToken cancellationToken) |
| | | 32 | | { |
| | | 33 | | // Run the alterations. |
| | 0 | 34 | | var results = await _alterationRunner.RunAsync(request.WorkflowInstanceIds, request.Alterations, cancellationTok |
| | | 35 | | |
| | | 36 | | // Schedule each successfully updated workflow containing scheduled work. |
| | 0 | 37 | | await _workflowDispatcher.DispatchAsync(results, cancellationToken); |
| | | 38 | | |
| | | 39 | | // Write response. |
| | 0 | 40 | | var response = new Response(results); |
| | 0 | 41 | | await Send.OkAsync(response, cancellationToken); |
| | 0 | 42 | | } |
| | | 43 | | } |