< Summary

Information
Class: Elsa.Workflows.Runtime.ActivationValidators.SingletonStrategy
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/ActivationValidators/SingletonStrategy.cs
Line coverage
100%
Covered lines: 9
Uncovered lines: 0
Coverable lines: 9
Total lines: 27
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/ActivationValidators/SingletonStrategy.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 doesn't already exist.
 9/// </summary>
 10[Display(Name = "Singleton", Description = "Only allow new workflow instances if a running one of the same workflow defi
 74211public class SingletonStrategy(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    {
 218        var filter = new WorkflowInstanceFilter
 219        {
 220            DefinitionId = context.Workflow.Identity.DefinitionId,
 221            WorkflowStatus = WorkflowStatus.Running
 222        };
 23
 224        var count = await workflowInstanceStore.CountAsync(filter);
 225        return count == 0;
 226    }
 27}