| | | 1 | | using Elsa.Mediator.Contracts; |
| | | 2 | | using Elsa.Common.Multitenancy; |
| | | 3 | | using Elsa.Workflows.Management.Activities.WorkflowDefinitionActivity; |
| | | 4 | | using Elsa.Workflows.Management.Contracts; |
| | | 5 | | using Elsa.Workflows.Runtime.Notifications; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | |
| | | 8 | | namespace Elsa.Workflows.Runtime.Handlers; |
| | | 9 | | |
| | | 10 | | /// <summary> |
| | | 11 | | /// Refreshes the <see cref="IActivityRegistry"/> for the <see cref="WorkflowDefinitionActivityProvider"/> provider when |
| | | 12 | | /// </summary> |
| | | 13 | | [PublicAPI] |
| | 734 | 14 | | public class RefreshActivityRegistry( |
| | 734 | 15 | | IWorkflowDefinitionActivityRegistryUpdater workflowDefinitionActivityRegistryUpdater, |
| | 734 | 16 | | IWorkflowDefinitionRegistryGenerationStore generationStore, |
| | 734 | 17 | | ITenantAccessor tenantAccessor) : INotificationHandler<WorkflowDefinitionsReloaded> |
| | | 18 | | { |
| | | 19 | | /// <inheritdoc /> |
| | | 20 | | public async Task HandleAsync(WorkflowDefinitionsReloaded notification, CancellationToken cancellationToken) |
| | | 21 | | { |
| | 3692 | 22 | | foreach (var reloadedWorkflowDefinition in notification.ReloadedWorkflowDefinitions) |
| | 1625 | 23 | | await UpdateDefinition(reloadedWorkflowDefinition.DefinitionVersionId, reloadedWorkflowDefinition.UsableAsAc |
| | | 24 | | |
| | | 25 | | // Reload notifications do not carry tenant identity. The reloaded set can contain |
| | | 26 | | // agnostic definitions, so notify every tenant through the shared generation. |
| | 221 | 27 | | var tenantId = tenantAccessor.TenantId.NormalizeTenantId(); |
| | 221 | 28 | | if (tenantId != Tenant.AgnosticTenantId) |
| | 220 | 29 | | await generationStore.IncrementAsync(Tenant.AgnosticTenantId, cancellationToken); |
| | | 30 | | |
| | 221 | 31 | | await generationStore.IncrementAsync(tenantId, cancellationToken); |
| | 221 | 32 | | } |
| | | 33 | | |
| | | 34 | | private Task UpdateDefinition(string definitionVersionId, bool? usableAsActivity) |
| | | 35 | | { |
| | | 36 | | // A workflow should remain in the activity registry unless no longer being marked as an activity. |
| | 1625 | 37 | | if (usableAsActivity.GetValueOrDefault()) |
| | 144 | 38 | | return workflowDefinitionActivityRegistryUpdater.AddToRegistry(definitionVersionId); |
| | | 39 | | |
| | 1481 | 40 | | workflowDefinitionActivityRegistryUpdater.RemoveDefinitionVersionFromRegistry(definitionVersionId); |
| | 1481 | 41 | | return Task.CompletedTask; |
| | | 42 | | } |
| | | 43 | | } |