Switch

Overview

The switch is a conditional judgment node, decide the branch executes according to the value of global variable and the expression result written by the user.

Note: Execute expressions using javax.script.ScriptEngine.eval.

Create Task

  • Click Project Management -> Project Name -> Workflow Definition, and click the Create Workflow button to enter the DAG editing page.
  • Drag from the toolbar Switch - 图1 task node to canvas to create a task.

Note: After created a switch task, you must first configure the upstream and downstream, then configure the parameter of task branches.

Task Parameters

ParameterDescription
Node NameSet the name of the task. Node names within a workflow definition are unique.
Run flagIndicates whether the node can be scheduled normally. If it is not necessary to execute, you can turn on the prohibiting execution switch.
DescriptionDescribes the function of this node.
Task priorityWhen the number of worker threads is insufficient, they are executed in order from high to low according to the priority, and they are executed according to the first-in, first-out principle when the priority is the same.
Worker groupThe task is assigned to the machines in the worker group for execution. If Default is selected, a worker machine will be randomly selected for execution.
Task group nameThe group in Resources, if not configured, it will not be used.
Environment NameConfigure the environment in which to run the script.
Number of failed retriesThe number of times the task is resubmitted after failure. It supports drop-down and manual filling.
Failure Retry IntervalThe time interval for resubmitting the task if the task fails. It supports drop-down and manual filling.
Timeout alarmCheck Timeout Alarm and Timeout Failure. When the task exceeds the “timeout duration”, an alarm email will be sent and the task execution will fail.
Delay execution timeTask delay execution time.
ConditionYou can configure multiple conditions for the switch task. When the conditions are satisfied, execute the configured branch. You can configure multiple different conditions to satisfy different businesses.
Branch flowThe default branch flow, when all the conditions are not satisfied, execute this branch flow.

Task Example

This is demonstrated using one switch task and three shell tasks.

Create a workflow

Create a new switch task, and three shell tasks downstream. The shell task is not required. The switch task needs to be connected with the downstream task to configure the relationship before the downstream task can be selected.

switch_01

Set conditions

Configure the conditions and default branches. If the conditions are met, the specified branch will be taken. If the conditions are not met, the default branch will be taken. In the figure, if the value of the variable is “A”, the branch taskA is executed, if the value of the variable is “B”, the branch taskB is executed, and default is executed if both are not satisfied.

switch_02

Conditions use global variables, please refer to Global Parameter. The value of the global variable configured here is A.

switch_03

If executed correctly, then taskA will be executed correctly.

Execute

Execute and see if it works as expected. It can be seen that the specified downstream tasksA are executed as expected.

switch_04