< 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
10%
Covered lines: 1
Uncovered lines: 9
Coverable lines: 10
Total lines: 28
Line coverage: 10%
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%210%

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/// </summary>
 10[Display(Name = "Correlated singleton", Description = "Only allow new workflow instances if a running one of the same wo
 6811public 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    {
 018        var filter = new WorkflowInstanceFilter
 019        {
 020            DefinitionId = context.Workflow.Identity.DefinitionId,
 021            CorrelationId = context.CorrelationId,
 022            WorkflowStatus = WorkflowStatus.Running
 023        };
 24
 025        var count = await workflowInstanceStore.CountAsync(filter, context.CancellationToken);
 026        return count == 0;
 027    }
 28}