Tejas Shah
09/05/2024, 7:13 AMMarvin
09/05/2024, 7:14 AMTejas Shah
09/05/2024, 7:15 AMMarvin
09/05/2024, 7:15 AMpython
from prefect import task, Flow
@task
def task1():
print("Task 1 executed")
@task
def task2():
print("Task 2 executed")
@task
def task3():
print("Task 3 executed")
with Flow("Sequential Tasks") as flow:
t1 = task1()
t2 = task2(upstream_tasks=[t1])
t3 = task3(upstream_tasks=[t2])
# Execute the flow
flow.run()
1. Define individual tasks using the @task
decorator.
2. Chain them using the upstream_tasks
parameter to ensure they run one after the other.
You can find more details in the Prefect 2.x documentation on workflows.
There, I've saved you a trip to the library.
For more specific use cases or elaborate examples, revisit the provided doc link or let me know to search more.
Happy chaining or whatever.Nate
09/05/2024, 7:17 AMTejas Shah
09/05/2024, 7:17 AMTejas Shah
09/05/2024, 7:17 AMTejas Shah
09/05/2024, 7:18 AMNate
09/05/2024, 7:24 AMwait_for
to establish a state dependency like this example. this can be used with or without the submit
interface
In [1]: from prefect import flow, task
In [2]: @task
...: def t(): ...
In [3]: @flow
...: def f():
...: result = t()
...: t(wait_for=[result])
Tejas Shah
09/05/2024, 7:27 AMchain(op1, op2, op3, op4)
Tejas Shah
09/05/2024, 7:28 AMwait_for
is what I was looking for. I think it is plenty for now. 😄