| | | 1 | | using System.ComponentModel.DataAnnotations; |
| | | 2 | | using Elsa.Workflows.Management; |
| | | 3 | | using Elsa.Workflows.Management.Filters; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Workflows.Runtime.ActivationValidators; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Only allow new workflow instances if a running one of the same workflow definition and correlation ID doesn't alread |
| | | 9 | | /// </summary> |
| | | 10 | | [Display(Name = "Correlated singleton", Description = "Only allow new workflow instances if a running one of the same wo |
| | 68 | 11 | | public class CorrelatedSingletonStrategy(IWorkflowInstanceStore workflowInstanceStore) : IWorkflowActivationStrategy |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Only allow a new instance if no running ones exist already. |
| | | 15 | | /// </summary> |
| | | 16 | | public async ValueTask<bool> GetAllowActivationAsync(WorkflowInstantiationStrategyContext context) |
| | | 17 | | { |
| | 0 | 18 | | var filter = new WorkflowInstanceFilter |
| | 0 | 19 | | { |
| | 0 | 20 | | DefinitionId = context.Workflow.Identity.DefinitionId, |
| | 0 | 21 | | CorrelationId = context.CorrelationId, |
| | 0 | 22 | | WorkflowStatus = WorkflowStatus.Running |
| | 0 | 23 | | }; |
| | | 24 | | |
| | 0 | 25 | | var count = await workflowInstanceStore.CountAsync(filter, context.CancellationToken); |
| | 0 | 26 | | return count == 0; |
| | 0 | 27 | | } |
| | | 28 | | } |