What would you like to be added:
Expose the full set of active (non-terminal) WorkflowInstances tracked by a WorkflowDefinition, similar to the existing scheduledInstances() accessor.
WorkflowDefinition (impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java) already keeps every running instance in an internal map:
private Map<String, WorkflowInstance> activeInstances = new ConcurrentHashMap<>();
but the only public accessor is a single-instance lookup:
public Optional<WorkflowInstance> activeInstance(String instanceId)
There's no way to enumerate all active instances for a definition. Meanwhile, scheduledInstances already has a bulk accessor that returns an unmodifiable view:
public Collection<WorkflowInstance> scheduledInstances() {
return Collections.unmodifiableCollection(scheduledInstances);
}
I'd like to add an equivalent for active instances, e.g.:
public Collection<WorkflowInstance> activeInstances() {
return Collections.unmodifiableCollection(activeInstances.values());
}
Why is this needed:
In quarkus-flow we're adding a REST endpoint that lists the in-memory active workflow instances on a runner pod, so a rebalancer service can tell which instances are actively being processed on a given pod vs. only persisted in the DB (see PR #892).
Since the SDK doesn't expose this today, the current implementation duplicates the tracking with a separate ActiveInstanceRegistry that listens to WorkflowExecutionListener lifecycle events and maintains its own copy of the same data WorkflowDefinition already holds internally.
As pointed out in review feedback by @fjtirado, this duplication isn't necessary — WorkflowDefinition is already the source of truth for active instances, it just isn't public. Exposing activeInstances() (mirroring scheduledInstances()) would let quarkus-flow (and other SDK consumers) query this directly instead of re-implementing the same bookkeeping, and let us drop ActiveInstanceRegistry in favor of the new method.
What would you like to be added:
Expose the full set of active (non-terminal)
WorkflowInstances tracked by aWorkflowDefinition, similar to the existingscheduledInstances()accessor.WorkflowDefinition(impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowDefinition.java) already keeps every running instance in an internal map:but the only public accessor is a single-instance lookup:
There's no way to enumerate all active instances for a definition. Meanwhile,
scheduledInstancesalready has a bulk accessor that returns an unmodifiable view:I'd like to add an equivalent for active instances, e.g.:
Why is this needed:
In quarkus-flow we're adding a REST endpoint that lists the in-memory active workflow instances on a runner pod, so a rebalancer service can tell which instances are actively being processed on a given pod vs. only persisted in the DB (see PR #892).
Since the SDK doesn't expose this today, the current implementation duplicates the tracking with a separate
ActiveInstanceRegistrythat listens toWorkflowExecutionListenerlifecycle events and maintains its own copy of the same dataWorkflowDefinitionalready holds internally.As pointed out in review feedback by @fjtirado, this duplication isn't necessary —
WorkflowDefinitionis already the source of truth for active instances, it just isn't public. ExposingactiveInstances()(mirroringscheduledInstances()) would let quarkus-flow (and other SDK consumers) query this directly instead of re-implementing the same bookkeeping, and let us dropActiveInstanceRegistryin favor of the new method.