Skip to main content

Terminate Workflow

The Terminate Workflow task allows for the termination of other workflows using their workflow (execution) IDs. It allows users to terminate single or multiple workflows with optional parameters for specifying termination reasons and triggering failure workflows.

Task parameters

Configure these parameters for the Terminate Workflow task.

ParameterDescriptionRequired/ Optional
inputParameters. workflowIdAn array of one or more workflow (execution) IDs of the workflow executions to be terminated. It can be passed as a dynamic variable.Required.
inputParameters. terminationReasonThe reason for terminating the workflow(s), which will provide the context of the termination. It can be passed as a dynamic variable.Optional.
triggerFailureWorkflowWhether the failure workflow for the terminated workflow will be triggered. Accepted values:
  • true—The failure workflow will be triggered.
  • false—The default option. The failure workflow will not be triggered.
Required.

The following are generic configuration parameters that can be applied to the task and are not specific to the Terminate Workflow task.

Other generic parameters

Here are other parameters for configuring the task behavior.

ParameterDescriptionRequired/ Optional
optionalWhether the task is optional.

If set totrue, any task failure is ignored, and the workflow continues with the task status updated to COMPLETED_WITH_ERRORS. However, the task must reach a terminal state. If the task remains incomplete, the workflow waits until it reaches a terminal state before proceeding.
Optional.

Task configuration

This is the task configuration for a Terminate Workflow task.

{
"name": "TW",
"taskReferenceName": "TW_ref",
"inputParameters": {
"workflowId": [
"${workflow.input.workflowIds}"
],
"terminationReason": "Terminated due to xxxxxx.",
"triggerFailureWorkflow": false
},
"type": "TERMINATE_WORKFLOW"
}

Task output

The Terminate Workflow task will return the following parameters.

ParameterDescription
terminatedWorkflowsAn array of the workflow (execution) IDs corresponding to the terminated workflows.

Adding a Terminate Workflow task in UI

To add a Terminate Workflow task:

  1. In your workflow, select the (+) icon and add a Terminate Workflow task.
  2. Enter the Workflow IDs along with the termination reason.
  3. (Optional) Check Trigger Failure Workflow if needed.

Adding wait task

Examples

Here are some examples for using the Terminate Workflow task.

Using the Terminate Workflow task in a workflow

To demonstrate the Terminate Workflow task, consider the following workflow, which represents a running workflow that will later be terminated.

To create a workflow:

  1. Go to Definitions > Workflow, from the left navigation menu on your Conductor cluster.
  2. Select + Define workflow.
  3. In the Code tab, paste the following workflow definition:
{
"name": "WorkflowToBeTerminated",
"description": "Sample workflow to demonstrate termination",
"version": 1,
"tasks": [
{
"name": "wait",
"taskReferenceName": "wait_ref",
"inputParameters": {},
"type": "WAIT"
}
],
"schemaVersion": 2
}
  1. Save the workflow and select Execute to run it.

This workflow waits indefinitely, allowing it to remain in a running state. Note the workflow ID of this execution.

Getting workflow ID

Next, create a workflow with a Terminate Workflow task using the following workflow definition:

{
"name": "WorkflowToTerminateAnotherWorkflow",
"description": "Sample workflow to demonstrate the Terminate Workflow task",
"version": 1,
"tasks": [
{
"name": "terminate_workflow",
"taskReferenceName": "terminate_workflow_ref",
"type": "TERMINATE_WORKFLOW",
"inputParameters": {
"workflowId": [
"${workflow.input.workflowId}"
],
"terminationReason": "The workflow is terminated by the Terminate Workflow task."
}
}
],
"inputParameters": [
"workflowId"
],
"schemaVersion": 2
}

Let’s run this workflow by going to the Run tab and entering the previous workflow ID as the input parameter. For example:

{
"workflowId": "<YOUR-WORKFLOW-ID>"
}

Once completed, the Terminate Workflow task’s output displays the workflow ID of the terminated workflow.

Terminate Workflow - Successful execution

To verify this, go to Executions > Workflow and search for the terminated workflow ID. Select the workflow ID to view the execution.

Verifying the terminated workflow from executions

At the top of the execution details, you can view the termination reason that was provided in the Terminate Workflow task.

View of the terminated workflow

Terminate workflow with Trigger Failure Workflow enabled

To demonstrate the Terminate Workflow task with Trigger Failure Workflow enabled, first create a failure workflow, then create and run a workflow that references it, and finally terminate that workflow from a separate workflow.

Step 1: Create the failure workflow

To create a workflow:

  1. Go to Definitions > Workflow, from the left navigation menu on your Conductor cluster.
  2. Select + Define workflow.
  3. In the Code tab, paste the following workflow definition:
{
"name": "failure",
"description": "Failure workflow",
"version": 1,
"tasks": [
{
"name": "failure_task",
"taskReferenceName": "failure_task_ref",
"inputParameters": {},
"type": "SIMPLE"
}
],
"schemaVersion": 2
}
  1. Save the workflow.

Step 2: Create a workflow that uses the failure workflow

Create another workflow using the following workflow definition:

{
"name": "WorkflowToBeTerminated",
"description": "Sample workflow to demonstrate termination",
"version": 1,
"tasks": [
{
"name": "wait",
"taskReferenceName": "wait_ref",
"inputParameters": {},
"type": "WAIT"
}
],
"failureWorkflow": "failure",
"schemaVersion": 2
}

This workflow has the Failure/Compensation workflow configured and set to the workflow created in the previous step.

Workflow to be terminated

Save and run the workflow. Note the workflow ID of this execution.

Getting the workflow (execution) ID of the workflow to be terminated

Step 3: Create a workflow with the Terminate Workflow task

Next, create a workflow with a Terminate Workflow task using the following workflow definition, with triggerFailureWorkflow set to true:

{
"name": "WorkflowToTerminateAnotherWorkflow",
"description": "Sample workflow to demonstrate the Terminate Workflow task",
"version": 1,
"tasks": [
{
"name": "terminate_workflow",
"taskReferenceName": "terminate_workflow_ref",
"inputParameters": {
"workflowId": [
"${workflow.input.workflowId}"
],
"terminationReason": "The workflow is terminated by the Terminate Workflow task and failure workflow is triggered.",
"triggerFailureWorkflow": true
},
"type": "TERMINATE_WORKFLOW"
}
],
"inputParameters": [
"workflowId"
],
"schemaVersion": 2
}

The input parameters for the Terminate Workflow task contain the following configuration:

  • The above running workflow’s workflow (execution) ID is provided as an input parameter, along with a termination reason.
  • The option to trigger failure workflow is enabled.

Now, let’s run this workflow by going to the Run tab and entering the previous workflow ID as the input parameter. For example:

{
"workflowId": "<YOUR-WORKFLOW-ID>"
}

Once completed, the Terminate Workflow task’s output displays the workflow ID of the terminated workflow.

Running terminate workflow demo

Upon completion, the workflow with this ID will be terminated. To view the execution of the terminated workflow, go to Executions > Workflow and search using the workflow (execution) ID.

Execution of the terminated workflow

At the top of the execution details, you can view the termination reason that was provided and see that the failure workflow has been triggered. Select Triggered failure workflow to view the failure workflow’s execution.

Triggered failure workflow