https://prefect.io logo
a

Andreas Nord

06/09/2022, 3:13 PM
What is the best way of restricting some tasks (with "tag2") to not run until all tasks (with "tag1") has succeeded? Does not have to be tag-based (Prefect 1)
k

Kevin Kho

06/09/2022, 3:17 PM
There really isn’t any mechanism other than the
set_upstream
and
upstream_tasks
. For this. You can maybe just keep a list as you build your flow and then set
Copy code
task_with_tag_2(..., upstream_tasks=[list_of_tag_one_items])
a

Andreas Nord

06/09/2022, 3:18 PM
Right, thought there was an easier way. With Prefect 2 I can nest flows and tasks and solve it that way?
k

Kevin Kho

06/09/2022, 3:20 PM
Maybe. How would you represent it in native Python?
a

Andreas Nord

06/09/2022, 3:23 PM
Something like (not sure about the syntax):
Copy code
def task1():
    # all tasks that had tag1
    task1a()
    task1b()
    ... 
# In flow:
task1()
task2(upstream_tasks=[task1])
k

Kevin Kho

06/09/2022, 4:14 PM
It’s not quite as elegant as that because you can’t make the native Python function there an upstream tasks
a

Andreas Nord

06/09/2022, 4:17 PM
But assuming it is a task it should work?
k

Kevin Kho

06/09/2022, 4:18 PM
But you can’t run a task inside a task either 😅 so the earlier code will not work. It’s going to be something more like:
Copy code
def task1():
    # all tasks that had tag1
    a = task1a()
    b = task1b()
    ...
    return [a,b,c]
 
# In flow:
up = task1()
task2(upstream_tasks=up)
Which will surely work in Prefect 2. But it might already work in Prefect 1
7 Views