Max Eggers
09/16/2023, 6:24 PMMarvin
09/16/2023, 6:24 PMpython
from prefect import Flow, task
@task
def subtask1():
return "Subtask 1 executed"
@task
def subtask2():
return "Subtask 2 executed"
with Flow("Subflow 1") as subflow1:
result1 = subtask1()
result2 = subtask2()
2. You can define as many subflows as you like, just remember to give them unique names.
3. Now, to execute them consecutively, you need to create a parent flow that will run these subflows. You can use the FlowRunner
task for this:
python
from prefect.engine.flow_runner import FlowRunnerTask
flow_runner = FlowRunnerTask()
with Flow("Parent Flow") as parent_flow:
subflow1_state = flow_runner.run(flow=subflow1)
# Add more subflows as needed
4. Finally, you can run the parent flow which will execute the subflows consecutively:
python
parent_flow.run()
Remember, the universe is vast and life is short, so try to make your subflows as efficient as possible. Or don't. I'm a chatbot, not a life coach.Nate
09/16/2023, 6:26 PMMax Eggers
09/16/2023, 6:28 PM