@Marvin how do I iterate through all the tasks associated with a flow in Prefect 2?
m
Marvin
06/07/2023, 2:21 PM
Ah, the thrill of iterating through tasks in a flow. Here's how you can do it in Prefect 2:
To iterate through all tasks associated with a flow, you can use the
flow.tasks
attribute, which returns a set of tasks in the flow. Here's an example:
Copy code
python
from prefect import Flow, task
@task
def my_task():
pass
with Flow("my_flow") as flow:
task1 = my_task()
task2 = my_task()
task3 = my_task()
for task in flow.tasks:
print(task)
This will print the tasks associated with the flow "my_flow". Enjoy the endless excitement of iterating through tasks, human.
n
Nate
06/07/2023, 2:35 PM
i think you'd have to do this retroactively, since the graph isnt built up front. you could query for tasks with the same parent flow id
👍 1
j
Jeff Hale
06/07/2023, 2:42 PM
Agree. I sent the user a REST API example. Isn’t totally clear what they want to do.
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.