| | | 1 | | using Elsa.Common.Entities; |
| | | 2 | | using Elsa.Common.Models; |
| | | 3 | | using Elsa.Mediator.Contracts; |
| | | 4 | | using Elsa.Workflows.Management; |
| | | 5 | | using Elsa.Workflows.Management.Entities; |
| | | 6 | | using Elsa.Workflows.Management.Filters; |
| | | 7 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 8 | | using Elsa.Workflows.Runtime.Requests; |
| | | 9 | | using Elsa.Workflows.Runtime.Responses; |
| | | 10 | | |
| | | 11 | | namespace Elsa.Workflows.Runtime; |
| | | 12 | | |
| | | 13 | | /// <inheritdoc /> |
| | 2 | 14 | | public class WorkflowDefinitionsRefresher(IWorkflowDefinitionStore store, ITriggerIndexer triggerIndexer, INotificationS |
| | | 15 | | { |
| | | 16 | | /// <inheritdoc /> |
| | | 17 | | public async Task<RefreshWorkflowDefinitionsResponse> RefreshWorkflowDefinitionsAsync(RefreshWorkflowDefinitionsRequ |
| | | 18 | | { |
| | 1 | 19 | | var filter = new WorkflowDefinitionFilter |
| | 1 | 20 | | { |
| | 1 | 21 | | DefinitionIds = request.DefinitionIds, |
| | 1 | 22 | | VersionOptions = VersionOptions.Published |
| | 1 | 23 | | }; |
| | | 24 | | |
| | 1 | 25 | | var currentPage = 0; |
| | 1 | 26 | | var processedWorkflowDefinitions = new List<WorkflowDefinition>(); |
| | 1 | 27 | | var batchSize = request.BatchSize; |
| | 1 | 28 | | var order = new WorkflowDefinitionOrder<string>(x => x.Id, OrderDirection.Ascending); |
| | | 29 | | |
| | 1 | 30 | | while (!cancellationToken.IsCancellationRequested) |
| | | 31 | | { |
| | 1 | 32 | | var pageArgs = PageArgs.FromPage(currentPage, batchSize); |
| | 1 | 33 | | var definitions = await store.FindManyAsync(filter, order, pageArgs, cancellationToken); |
| | | 34 | | |
| | 1 | 35 | | if (definitions.Items.Count == 0) |
| | | 36 | | break; |
| | | 37 | | |
| | 1 | 38 | | await IndexWorkflowTriggersAsync(definitions.Items, cancellationToken); |
| | 1 | 39 | | processedWorkflowDefinitions.AddRange(definitions.Items); |
| | 1 | 40 | | currentPage++; |
| | | 41 | | |
| | 1 | 42 | | if (definitions.Items.Count < batchSize) |
| | | 43 | | break; |
| | 0 | 44 | | } |
| | | 45 | | |
| | 2 | 46 | | var processedWorkflowDefinitionIds = processedWorkflowDefinitions.Select(x => x.DefinitionId).ToList(); |
| | 1 | 47 | | var notification = new WorkflowDefinitionsRefreshed(processedWorkflowDefinitionIds); |
| | 1 | 48 | | await notificationSender.SendAsync(notification, cancellationToken); |
| | 1 | 49 | | return new(processedWorkflowDefinitionIds, request.DefinitionIds?.Except(processedWorkflowDefinitionIds)?.ToList |
| | 1 | 50 | | } |
| | | 51 | | |
| | | 52 | | private async Task IndexWorkflowTriggersAsync(IEnumerable<WorkflowDefinition> definitions, CancellationToken cancell |
| | | 53 | | { |
| | 4 | 54 | | foreach (var definition in definitions) |
| | 1 | 55 | | await triggerIndexer.IndexTriggersAsync(definition, cancellationToken); |
| | 1 | 56 | | } |
| | | 57 | | } |