<Prefect’s documentation> says the following: &gt;...
# prefect-community
o
Prefect’s documentation says the following:
Create a flow as a context manager and call your tasks on each other as if they were regular functions. Prefect will track each function call and build up a computational graph that represents your workflow. Critically, no tasks are actually executed at this time.
1
z
Yeah, calling the tasks here just signals that they should be added to the DAG.
o
It’s interesting from implementation perspective how is it achieved
It’s like changing Python’s core flow, would never imagined that Python is that flexible and allows to hook post/pre any function call
r
Everything called inside the context manager is a Task (whether created imperatively or using the
@task
decorator), and Task is Callable (i.e., it implements
__call__
), which makes it easy to do anything you'd like before or after calling the original function.
o
Gotcha, thanks!
r
Keep in mind that the docs page you linked is for Prefect 1. If you're just starting with Prefect as you mentioned in your previous thread, you'll want to use Prefect 2, which doesn't use a flow context manager - instead, you decorate a function with
@flow
.
🙏 1
o
Thanks @Ryan Peden for the comment. Is it mature enough like 1.0? I am going to run this in production very soon
r
Yes - many others are happily running Prefect 2 in production 😄
👍 1
o
so I guess 1.0 is deprecated/EOL’d soon and most of the efforts of the core are focused on Prefect 2.0
r
Prefect 1 is still maintained right now, but Prefect 2 is the best choice for new projects.
o
Thanks a lot Ryan.
r
You're welcome! 😄