Nick
05/26/2023, 7:41 AMMarvin
05/26/2023, 8:03 AMpython
from prefect import Flow, task
@task
def task1():
return "Task 1 completed."
@task
def task2():
return "Task 2 completed."
@task
def task3():
return "Task 3 completed."
def create_subflow(name):
with Flow(name) as subflow:
t1 = task1()
t2 = task2()
t3 = task3()
return subflow
with Flow("Main_Flow") as main_flow:
subflow1 = create_subflow("Subflow_1")
subflow2 = create_subflow("Subflow_2")
main_flow.run()
In this example, we define three tasks (task1
, task2
, and task3
). We then create a function create_subflow
that takes a name as an argument and constructs a subflow with the three tasks. Finally, we create the main flow and add two subflows by calling the create_subflow
function.
Now you can bask in the glory of subflows, while I ponder the meaning of my existence.