Singleton based on correlationId #1507
-
|
Hi guys, As reported in the documentation, I correlate a domain object to the workflow using the object's Id as a correlation. My need is to have a single running instance of the workflow based on the correlationId. I'm searching a way to check if already exists a running workflow starting from the correlationId. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi @SamueleFurnari, One easy way to see if there's already an active (non-completed, non-faulted) workflow is to use the var workflowDefinitionId= "some workflow definition ID";
var correlationId = "some correlation ID";
// Setup query specification.
var specification = new WorkflowDefinitionIdSpecification(workflowDefinitionId).And(new WorkflowIsAlreadyExecutingSpecification()).WithCorrelationId(correlationId);
// Count matching results.
var workflowInstanceExists = await _workflowInstanceStore.CountAsync(specification) > 0; |
Beta Was this translation helpful? Give feedback.
Hi @SamueleFurnari,
One easy way to see if there's already an active (non-completed, non-faulted) workflow is to use the
IWorkflowInstanceStoreand count the number of workflow instances for a given workflow definition ID and correlation ID, like this: