< Summary

Information
Class: Elsa.Workflows.Runtime.ActivationValidators.CorrelatedSingletonStrategy
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/ActivationValidators/CorrelatedSingletonStrategy.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 32
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetAllowActivationAsync()100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/ActivationValidators/CorrelatedSingletonStrategy.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using Elsa.Workflows.Management;
 3using Elsa.Workflows.Management.Filters;
 4
 5namespace 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/// A non-blank correlation ID is required for this strategy.
 10/// </summary>
 11[Display(Name = "Correlated singleton", Description = "Only allow new workflow instances if a running one of the same wo
 74712public class CorrelatedSingletonStrategy(IWorkflowInstanceStore workflowInstanceStore) : IWorkflowActivationStrategy
 13{
 14    /// <summary>
 15    /// Only allow a new instance if no running ones exist already.
 16    /// </summary>
 17    public async ValueTask<bool> GetAllowActivationAsync(WorkflowInstantiationStrategyContext context)
 18    {
 1919        if (string.IsNullOrWhiteSpace(context.CorrelationId))
 420            throw new ArgumentException("A non-blank correlation ID is required when using CorrelatedSingletonStrategy."
 21
 1522        var filter = new WorkflowInstanceFilter
 1523        {
 1524            DefinitionId = context.Workflow.Identity.DefinitionId,
 1525            CorrelationId = context.CorrelationId,
 1526            WorkflowStatus = WorkflowStatus.Running
 1527        };
 28
 1529        var count = await workflowInstanceStore.CountAsync(filter, context.CancellationToken);
 1530        return count == 0;
 1531    }
 32}