| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Workflows.Management; |
| | | 3 | | using Elsa.Workflows.Runtime.Models; |
| | | 4 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 5 | | |
| | | 6 | | namespace Elsa.Workflows.Runtime; |
| | | 7 | | |
| | | 8 | | /// <inheritdoc /> |
| | 170 | 9 | | public class DefaultRegistriesPopulator( |
| | 170 | 10 | | IWorkflowDefinitionStorePopulator workflowDefinitionStorePopulator, |
| | 170 | 11 | | IActivityRegistryPopulator activityRegistryPopulator, |
| | 170 | 12 | | INotificationSender notificationSender) : IRegistriesPopulator |
| | | 13 | | { |
| | | 14 | | /// <inheritdoc /> |
| | | 15 | | public async Task PopulateAsync(CancellationToken cancellationToken = default) |
| | | 16 | | { |
| | | 17 | | // Stage 1: Populate the activity registry. |
| | | 18 | | // Because workflow definitions can be used as activities, we need to make sure that the activity registry is po |
| | 170 | 19 | | await activityRegistryPopulator.PopulateRegistryAsync(cancellationToken); |
| | | 20 | | |
| | | 21 | | // Stage 2: Populate the workflow definition store. |
| | 170 | 22 | | await workflowDefinitionStorePopulator.PopulateStoreAsync(false, cancellationToken); |
| | | 23 | | |
| | | 24 | | // Stage 3: Re-populate the activity registry. |
| | | 25 | | // After the workflow definition store has been populated, we need to re-populate the activity registry to make |
| | 170 | 26 | | await activityRegistryPopulator.PopulateRegistryAsync(cancellationToken); |
| | | 27 | | |
| | | 28 | | // Stage 4. Re-update the workflow definition store with the current set of activities. |
| | | 29 | | // Finally, we need to re-populate the workflow definition store to make sure that the workflow definitions are |
| | 170 | 30 | | var workflowDefinitions = await workflowDefinitionStorePopulator.PopulateStoreAsync(true, cancellationToken); |
| | | 31 | | |
| | | 32 | | // Stage 5: Publish a notification that the workflow definitions have been reloaded. This ensures other replicat |
| | 170 | 33 | | var reloadedWorkflowDefinitions = workflowDefinitions.Select(ReloadedWorkflowDefinition.FromDefinition).ToList() |
| | 170 | 34 | | var notification = new WorkflowDefinitionsReloaded(reloadedWorkflowDefinitions); |
| | 170 | 35 | | await notificationSender.SendAsync(notification, cancellationToken); |
| | 170 | 36 | | } |
| | | 37 | | } |