What is the best way to count the number of workflow running instances?

Hi,
I want to count the number of running instances of a workflow definition. What is the best way to do it? Can I run a workflow multiple times with the same workflow id but different run ids? So that I can query the count of workflow instances with the same workflow id. (tried seems not working)

I want to count the number of running instances of a workflow definition. What is the best way to do it?

Each workflow has a specific type. Workflow executions that you create inherit that type and have a status associated with them. If you have enhanced visibility enabled (Elasticsearch) you could use ListWorkflowExecutions
api to query workflows of a specific type and its status for a specific namespace. A sample query could be for example:

WorkflowType="MyWorkflowType" AND ExecutionStatus="Running"

(you can try this query inside the web-ui as well (click on the “Advanced” button on the top-right corner).
Don’t know which Temporal SDK you are using to provide an example.

Can I run a workflow multiple times with the same workflow id but different run ids?

You cannot have two workflow executions running at the same time that have the same workflow id.
Specific details on this can be set via WorkflowIdReusePolicy (via WorkflowOptions), with default behavior being that you can start a new execution with the same id only if previous one with that id completed (is no longer running).

So that I can query the count of workflow instances with the same workflow id. (tried seems not working)

You should be able to use ListWorkflowExecutions to query for specific workflow id, regardless of the execution status. Sample query:

WorkflowId="myWorkflowId"

Thanks for the reply Is the WorkflowType the workflow name? I registered the workflow with a given name

For Java SDK, its by default the short class name of your workflow interface, and can be specifically set via @WorkflowMethod annotation (name param).

For Go SDK, its by default the name of your workflow function, and can be specifically set via RegisterWorkflowOptions->Name.

You can see the workflow type also in the “NAME” column of the web ui.

Yep, that is what i meant.
but this seems not to work for me, since i am using this GitHub - checkr/states-language-cadence: States Language on Cadence so I only have one workflow to be registered. All my workflow are written in ASL. Is there any other options that i can pass in like a tag or something to be able to identify the different workflows?

You can create multiple executions for the same workflow type.
The original question was about the workflow id.
In your case, you should set each workflow id to some unique value that can be based on really anything that you want, some unique business value (like customer id for example). If you don’t specifically set the workflow id when you start a new execution, Temporal will set it to an uuid that should be unique for your namespace used.

specify unique workflow id seems not to work, since i will run multiple workflow instance at the same time. Here is my configuration: I have a ASL workflow (a state machine in GitHub - checkr/states-language-cadence: States Language on Cadence) registered in Temporal, and I have a workflow written in ASL say “hello-asl”, this workflow can be triggered to run in many places, each running instance should have a unique workflow id, right?

So I want to list all workflows instances (all status) associated with “hello-asl”, is it doable?

I am not familiar with that particular project, but assume that you have a Temporal workflow that is executing the instructions in your DSL.
You can set that workflow type to be “hello-asl” and then if you cannot set a business-level id for each execution, either set you own unique id, or don’t set the workflow id so Temporal assigns one for you.

So I want to list all workflows instances (all status) associated with “hello-asl”, is it doable?

Yes, if you set “hello-asl” as the workflow type, you can use a search query, for example:

WorkflowType="hello-asl" AND ExecutionStatus="Running"

we are not only having “hello-asl”, we have 10s of workflows defined in ASL. So set the workflow type as hello-asl will not work

You can add a custom search attribute that contains your DSL workflow type.