You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/06/08 06:17:11 UTC

[dolphinscheduler] branch dev updated: [doc] Add switch task demo (#10247)

This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 7e39e0d48d [doc] Add switch task demo (#10247)
7e39e0d48d is described below

commit 7e39e0d48de07183f15504fa4e087c790f2479e7
Author: chuxing <92...@qq.com>
AuthorDate: Wed Jun 8 14:17:05 2022 +0800

    [doc] Add switch task demo (#10247)
    
    Co-authored-by: QuakeWang <45...@users.noreply.github.com>
---
 docs/docs/en/guide/task/switch.md |  44 +++++++++++++++++++++---------
 docs/docs/zh/guide/task/switch.md |  55 ++++++++++++++++++++++++++------------
 docs/img/switch_configure.jpg     | Bin 142764 -> 0 bytes
 docs/img/tasks/demo/switch_01.png | Bin 0 -> 117194 bytes
 docs/img/tasks/demo/switch_02.png | Bin 0 -> 141217 bytes
 docs/img/tasks/demo/switch_03.png | Bin 0 -> 148408 bytes
 docs/img/tasks/demo/switch_04.png | Bin 0 -> 125565 bytes
 7 files changed, 69 insertions(+), 30 deletions(-)

diff --git a/docs/docs/en/guide/task/switch.md b/docs/docs/en/guide/task/switch.md
index ad4a46e8eb..fb6e8bf456 100644
--- a/docs/docs/en/guide/task/switch.md
+++ b/docs/docs/en/guide/task/switch.md
@@ -1,10 +1,12 @@
 # Switch
 
 The switch is a conditional judgment node, decide the branch executes according to the value of [global variable](../parameter/global.md) and the expression result written by the user.
+**Note** Execute expressions using javax.script.ScriptEngine.eval.
 
-## Create
+## 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 <img src="../../../../img/switch.png" width="20"/> task node to canvas to create a task. 
 
-Drag from the toolbar <img src="../../../../img/switch.png" width="20"/>  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.
 
 ## Parameter
@@ -14,26 +16,42 @@ Drag from the toolbar <img src="../../../../img/switch.png" width="20"/>  task n
 - Descriptive information: Describe the function of the node.
 - Task priority: When the number of worker threads is insufficient, execute in the order of priority from high to low, and tasks with the same priority will execute in a first-in first-out order.
 - Worker grouping: Assign tasks to the machines of the worker group to execute. If `Default` is selected, randomly select a worker machine for execution.
+- Environment name: The environment in Security, if not configured, it will not be used.
+- Task group name: The group in Resources, if not configured, it will not be used.
 - Times of failed retry attempts: The number of times the task failed to resubmit. You can select from drop-down or fill-in a number.
 - Failed retry interval: The time interval for resubmitting the task after a failed task. You can select from drop-down or fill-in a number.
+- Delay execution time: Task delay execution time.
 - Timeout alarm: Check the timeout alarm and timeout failure. When the task runs exceed the "timeout", an alarm email will send and the task execution will fail.
 - Condition: You 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 flow: The default branch flow, when all the conditions are not satisfied, execute this branch flow.
 
-## Detail
+## Task Example
 
-Here we have three tasks, the dependencies are `A -> B -> [C, D]`, and `task_a` is a shell task and `task_b` is a switch task
+This is demonstrated using one switch task and three shell tasks.
 
-- In task A, a global variable named `id` is defined through [global variable](../parameter/global.md), and the declaration method is `${setValue(id=1)}`
-- Task B adds conditions and uses global variables declared upstream to achieve conditional judgment (Note: switch can get the global variables value, as long as its direct or indirect upstream have already assigned the global variables before switch acquires). We want to execute task C when `id = 1`, otherwise run task D
-  - Configure task C to run when the global variable `id=1`. Then edit `${id} == 1` in the condition of task B, and select `C` as branch flow
-  - For other tasks, select `D` as branch flow
+### Create a workflow
 
-The following shows the switch task configuration:
+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.
 
-![task-switch-configure](../../../../img/switch_configure.jpg)
+![switch_01](../../../../img/tasks/demo/switch_01.png)
 
-## Related Task
+### Set conditions
 
-[condition](conditions.md):[Condition](conditions.md)task mainly executes the corresponding branch based on the execution result status (success, failure) of the upstream node. 
-The [Switch](switch.md) task mainly executes the corresponding branch based on the value of the [global parameter](../parameter/global.md) and the judgment expression result written by the user.
\ No newline at end of file
+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](../../../../img/tasks/demo/switch_02.png)
+
+Conditions use global variables, please refer to [Global Parameter](../parameter/global.md).
+The value of the global variable configured here is A.
+
+![switch_03](../../../../img/tasks/demo/switch_03.png)
+
+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](../../../../img/tasks/demo/switch_04.png)
\ No newline at end of file
diff --git a/docs/docs/zh/guide/task/switch.md b/docs/docs/zh/guide/task/switch.md
index e9c2e3dae8..8b6af21b65 100644
--- a/docs/docs/zh/guide/task/switch.md
+++ b/docs/docs/zh/guide/task/switch.md
@@ -1,37 +1,58 @@
 # Switch
 
-Switch是一个条件判断节点,依据[全局变量](../parameter/global.md)的值和用户所编写的表达式判断结果执行对应分支。
+Switch 是一个条件判断节点,依据[全局变量](../parameter/global.md)的值和用户所编写的表达式判断结果执行对应分支。
+**注意**使用 javax.script.ScriptEngine.eval 执行表达式。
 
 ## 创建任务
 
-拖动工具栏中的<img src="../../../../img/switch.png" width="20"/>任务节点到画板中即能完成任务创建,**注意**switch任务创建后,要先配置上下游,才能配置任务分支的参数
+点击项目管理 -> 项目名称 -> 工作流定义,点击"创建工作流"按钮,进入 DAG 编辑页面。
+拖动工具栏中的 <img src="../../../../img/switch.png" width="20"/> 任务节点到画板中即能完成任务创建。
+**注意** switch 任务创建后,要先配置上下游,才能配置任务分支的参数。
 
 ## 任务参数
 
 - 节点名称:一个工作流定义中的节点名称是唯一的。
 - 运行标志:标识这个节点是否能正常调度,如果不需要执行,可以打开禁止执行开关。
 - 描述信息:描述该节点的功能。
-- 任务优先级:worker线程数不足时,根据优先级从高到低依次执行,优先级一样时根据先进先出原则执行。
-- Worker分组:任务分配给worker组的机器机执行,选择Default,会随机选择一台worker机执行。
+- 任务优先级:worker 线程数不足时,根据优先级从高到低依次执行,优先级一样时根据先进先出原则执行。
+- Worker 分组:任务分配给 worker 组的机器机执行,选择 Default,会随机选择一台 worker 机执行。
+- 环境名称:安全中心中配置的环境,不配置则不使用。
+- 任务组名称:资源中心中配置的任务组,不配置则不使用。
 - 失败重试次数:任务失败重新提交的次数,支持下拉和手填。
 - 失败重试间隔:任务失败重新提交任务的时间间隔,支持下拉和手填。
-- 超时告警:勾选超时告警、超时失败,当任务超过"超时时长"后,会发送告警邮件并且任务执行失败.
-- 条件:可以为switch任务配置多个条件,当条件满足时,就会执行指定的分支,可以配置多个不同的条件来满足不同的业务
-- 分支流转:默认的流转内容,当**条件**中的内容为全部不符合要求时,则运行**分支流转**中指定的分支
+- 延时执行时间:任务延迟执行的时间。
+- 超时告警:勾选超时告警、超时失败,当任务超过"超时时长"后,会发送告警邮件并且任务执行失败。
+- 条件:可以为 switch 任务配置多个条件,当条件满足时,就会执行指定的分支,可以配置多个不同的条件来满足不同的业务,使用字符串判断时需要使用""。
+- 分支流转:默认的流转内容,当**条件**中的内容为全部不符合要求时,则运行**分支流转**中指定的分支。
 
-## 详细流程
+## 任务样例
 
-假设我们三个任务,其依赖关系是 `A -> B -> [C, D]` 其中task_a是shell任务,task_b是switch任务
+这里使用一个 switch 任务以及三个 shell 任务来演示。
 
-- 任务A中通过[全局变量](../parameter/global.md)定义了名为`id`的全局变量,声明方式为`${setValue(id=1)}`
-- 任务B增加条件,使用上游声明的全局变量实现条件判断(注意:只要直接、非直接上游在switch运行前对全局变量赋值,switch运行时就可以获取该全局变量)。下面我们想要实现当id为1时,运行任务C,其他运行任务D
-  - 配置当全局变量`id=1`时,运行任务C。则在任务B的条件中编辑`${id} == 1`,分支流转选择`C`
-  - 对于其他任务,在分支流转中选择`D`
+### 创建工作流
 
-最终switch任务的配置如下
+新建 switch 任务,以及下游的三个 shell 任务。shell 任务没有要求。
+switch 任务需要和下游任务连线配置关系后,才可以进行下游任务的选择。
 
-![task-switch-configure](../../../../img/switch_configure.jpg)
+![switch_01](../../../../img/tasks/demo/switch_01.png)
 
-## 相关任务
+### 设置条件
+
+配置条件和默认分支,满足条件会走指定分支,都不满足则走默认分支。
+图中如果变量的值为 "A" 则执行分支 taskA,如果变量的值为 "B" 则执行分支 taskB ,都不满足则执行 default。
+
+![switch_02](../../../../img/tasks/demo/switch_02.png)
+
+条件使用了全局变量,请参考[全局变量](../parameter/global.md)。
+这里配置全局变量的值为 A。
+
+![switch_03](../../../../img/tasks/demo/switch_03.png)
+
+如果执行正确,那么 taskA 会被正确执行。
+
+### 执行
+
+执行,并且查看是否符合预期。可以看到符合预期,执行了指定的下游任务 taskA。
+
+![switch_04](../../../../img/tasks/demo/switch_04.png)
 
-[condition](conditions.md):[Condition](conditions.md)节点主要依据上游节点的执行状态(成功、失败)执行对应分支。Switch节点主要依据全局变量的值和用户所编写的表达式判断结果执行对应分支
diff --git a/docs/img/switch_configure.jpg b/docs/img/switch_configure.jpg
deleted file mode 100644
index 75bbd9c29e..0000000000
Binary files a/docs/img/switch_configure.jpg and /dev/null differ
diff --git a/docs/img/tasks/demo/switch_01.png b/docs/img/tasks/demo/switch_01.png
new file mode 100644
index 0000000000..c99c7edca4
Binary files /dev/null and b/docs/img/tasks/demo/switch_01.png differ
diff --git a/docs/img/tasks/demo/switch_02.png b/docs/img/tasks/demo/switch_02.png
new file mode 100644
index 0000000000..48aa3edec1
Binary files /dev/null and b/docs/img/tasks/demo/switch_02.png differ
diff --git a/docs/img/tasks/demo/switch_03.png b/docs/img/tasks/demo/switch_03.png
new file mode 100644
index 0000000000..d4509bac50
Binary files /dev/null and b/docs/img/tasks/demo/switch_03.png differ
diff --git a/docs/img/tasks/demo/switch_04.png b/docs/img/tasks/demo/switch_04.png
new file mode 100644
index 0000000000..57144049b0
Binary files /dev/null and b/docs/img/tasks/demo/switch_04.png differ