https://prefect.io logo
Title
s

Sunjay

11/08/2022, 2:14 PM
Hi guys, can someone tell me how to run each task of the that is being called using .map() function to run sequentially. Right now when I trigger, it creates a parallel exeution of all the individual tasks. i want to run them one after the other. Can someone please guide me with this ?
1
p

Peyton Runyan

11/08/2022, 2:50 PM
Hey there! You can just run them in a for-loop for sequential execution.
🙌 1
s

Sunjay

11/08/2022, 4:07 PM
Got it , Thanks@Peyton Runyan ! that worked. I was just trying the lazy apporach and re-use most of the my existing code in prefect 1 and migrate it to prefect 2 . @Peyton Runyan One last question. Can we set a task to success state, ie. based on a condition execute a task else set it to success and trigger the downstream.
j

Jeff Hale

11/08/2022, 6:40 PM
For your second question, Prefect 2 has a Completed run state and other states, but there is not a Success run state. In Prefect 2, you can just bring your Python code and raise and error if something fails - otherwise the next task in the flow will execute and you’ll be on your way.
🙌 1
s

Sunjay

11/15/2022, 12:08 PM
@Jeff Hale Can you please help me with this, How to explicitly set the state of a task to completed?
if conditions == 'Foo":
a = task1()
else:
"set task1() state to success" #i.e skip execution of task1()
b= task2() # task 2 wait_for the completed state of task1
So this is what I want to achieve in essence. I just wanted to know how to set the task1 state to completed as it can be skipped in case it doesn't meet a certain condition but the downstream job depends on the success state of the task1 using wait_for parameter.
j

Jeff Hale

11/15/2022, 1:43 PM
I don’t believe you can directly set the state. However, would something like the following do what you want?
def flow1(x):
    if x == "Foo":
        a = task1()
    else:
        a = "didn't run task1"
        b = task2()

    if a != "didn't run task1" and b:
       # do something
🙌 1
s

Sunjay

11/15/2022, 2:53 PM
@Jeff Hale Thank you so much