https://prefect.io logo
Title
a

Alfie

07/16/2020, 12:20 PM
Hi Team, a question about Functional API, can I specify upstream of a task manually? I want to have a task which is just wait for a few seconds, and it’s upstream of a task executes some actions
j

josh

07/16/2020, 12:22 PM
Hi @Alfie is this what you’re after?
In [4]: with Flow('dep') as flow:
   ...:     a = a()
   ...:     b = b()
   ...:     b.set_upstream(a)
(there’s also
.set_downstream()
)
a

Alfie

07/16/2020, 12:23 PM
thanks Josh! but my task is not a class, but a function with decorator
j

josh

07/16/2020, 12:23 PM
Yeah those are functions 🙂
In [1]: from prefect import task, Flow

In [2]: @task
   ...: def a():
   ...:     pass
   ...:

In [3]: @task
   ...: def b():
   ...:     pass
   ...:

In [4]: with Flow('dep') as flow:
   ...:     a = a()
   ...:     b = b()
   ...:     b.set_upstream(a)
a

Alfie

07/16/2020, 12:24 PM
great, let me try
j

josh

07/16/2020, 12:25 PM
The functional and imperative API are completely interchangeable!
a

Alfie

07/16/2020, 12:27 PM
got it. it works, thanks a lot!