Skip to content

Commit 46d7ea7

Browse files
committed
Add example about how to bulk create workflow
1 parent 3a8b809 commit 46d7ea7

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""
19+
This example show you how to create workflows in batch mode. After this example run, we will create 10
20+
workflows named `workflow:<workflow_num>`, and with 3 tasks named `task:<task_num>-workflow:<workflow_num>`
21+
in each workflow. Each workflow is linear shape as below, since we set `IS_CHAIN=True`
22+
23+
task:1-workflow:1 -> task:2-workflow:1 -> task:3-workflow:1
24+
"""
25+
26+
from pydolphinscheduler.core.process_definition import ProcessDefinition
27+
from pydolphinscheduler.tasks.shell import Shell
28+
29+
NUM_WORKFLOWS = 10
30+
NUM_TASKS = 5
31+
# Make sure your tenant exists in your operator system
32+
TENANT = "exists_tenant"
33+
# Whether task should dependent on pre one or not
34+
# False will create workflow with independent task, while True task will dependent on pre-task and dependence
35+
# link like `pre_task -> current_task -> next_task`, default True
36+
IS_CHAIN = True
37+
38+
for wf in range(0, NUM_WORKFLOWS):
39+
workflow_name = f"workflow:{wf}"
40+
41+
with ProcessDefinition(name=workflow_name, tenant=TENANT) as pd:
42+
for t in range(0, NUM_TASKS):
43+
task_name = f"task:{t}-workflow:{wf}"
44+
command = f"echo This is task {task_name}"
45+
task = Shell(name=task_name, command=command)
46+
47+
if IS_CHAIN and t > 0:
48+
pre_task_name = f"task:{t-1}-wf:{wf}"
49+
pd.get_one_task_by_name(pre_task_name) >> task
50+
51+
# We just submit workflow and task definition without set schedule time or run it manually
52+
pd.submit()

0 commit comments

Comments
 (0)