From 071b7a2f22768759095c083b7a3bef97fb01eb4e Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Fri, 9 Apr 2021 16:59:43 +0200 Subject: [PATCH] Fix TriggerWorkflows to select only Suspended instances --- .../Elsa.Core/Dispatch/Handlers/TriggerWorkflows.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/Elsa.Core/Dispatch/Handlers/TriggerWorkflows.cs b/src/core/Elsa.Core/Dispatch/Handlers/TriggerWorkflows.cs index 3aa163650..e0d071c50 100644 --- a/src/core/Elsa.Core/Dispatch/Handlers/TriggerWorkflows.cs +++ b/src/core/Elsa.Core/Dispatch/Handlers/TriggerWorkflows.cs @@ -7,6 +7,7 @@ using Elsa.Exceptions; using Elsa.Models; using Elsa.Persistence; using Elsa.Persistence.Specifications; +using Elsa.Persistence.Specifications.WorkflowInstances; using Elsa.Services; using Elsa.Triggers; using MediatR; @@ -62,11 +63,10 @@ namespace Elsa.Dispatch.Handlers if (handle == null) throw new LockAcquisitionException($"Failed to acquire a lock on {lockKey}"); - var correlatedWorkflowInstanceCount = !string.IsNullOrWhiteSpace(correlationId) ? await _workflowInstanceStore.CountAsync(new CorrelationIdSpecification(correlationId), cancellationToken) : 0; - - // Release lock before executing workflows. If we don't, we potentially enter a deadlock. - await handle.DisposeAsync(); - + var correlatedWorkflowInstanceCount = !string.IsNullOrWhiteSpace(correlationId) + ? await _workflowInstanceStore.CountAsync(new CorrelationIdSpecification(correlationId).WithStatus(WorkflowStatus.Suspended), cancellationToken) + : 0; + if (correlatedWorkflowInstanceCount > 0) { _logger.LogDebug("{WorkflowInstanceCount} existing workflows found with correlation ID '{CorrelationId}' will be queued for execution", correlatedWorkflowInstanceCount, correlationId);