Batch Terminate workflow with an API call

Hi Team, I found we have Temporal CLI - tctl to batch terminate workflows. But wondering if we have any Java API call to terminate all workflow via providing a workflow ID? Thanks!

Hi @Maggie, I believe the tctl batch terminate is currently the only option. Note that batch operations rely on enhanced visibility, so you have to enable Elasticsearch to use them.

Also note that when your workflows are “stuck” or have a possible bug, the standard way would be to fix the bug and redeploy. Another options could be to reset the workflow state to before the bad deployment, see here for more info. Hope this helps.

where would one find the --job_id required to run this command?

Hi @kmurph i think it’s a little bit confusing, “batch terminate” as shown in docs here is a command that terminates a running batch job. The job_id is an id of a batch job that you get when you start it.

For terminating multiple workflows you still need to use the batch start command with --batch_type flag set to terminate, for example:

tctl --ns default batch start --query "ExecutionStatus='Running'" --reason="my reasons" --batch_type=terminate

This batch job will be operating on 1 workflows.
Please confirm[Yes/No]:Yes
{
 "jobId": "7e47dbb8-358f-4c1d-b7c9-06613d916f73",
 "msg": "batch job is started"
}

the results will give you the jobId which later on you can use to terminate a long-running or stuck batch command. Hope this helps.

1 Like

Awesome, thanks for the clarification. This is what i was looking for.

Though still having a wee bit of trouble with this. When running this the Please Confirm step it automatically submits a response without pausing for one. Pretty sure this is something to do with our docker configuration, but haven’t quite figured it out.

Will update when we get it working