kiran
07/21/2021, 9:23 PMwith Flow(...):
context manager basically replace using a main()
function? i.e., instead of something like this:
from prefect import task, Flow
@task
def say_hello():
print("Hello, world!")
@task
def say_goodbye():
print("Goodbye, world!")
with Flow("My First Flow") as flow:
say_hello()
say_goodbye()
Would main()
be used with the context manager (and is it weird/redundant to do so)? i.e., would you decorate each function with @task
, order them in main()
(but not decorate main()
) and then call main()
from the context manager like so:
from prefect import task, Flow
@task
def say_hello():
print("Hello, world!")
@task
def say_goodbye():
print("Goodbye, world!")
def main():
say_hello()
say_goodbye()
if __name__ == "__main__":
with Flow("My First Flow") as flow:
main()
Thanks for any advice/insights on best practices around this!DK
07/21/2021, 9:48 PMemre
07/21/2021, 9:56 PMbuild_flow()
function.
2- Use main()
to configure my build_flow()
call, and also customize what to do with the built flow.
def build_flow(is_polite):
with Flow('abc') as f:
say_hello()
if is_polite:
say_goodbye()
return flow
def main():
# Here I can customize the flow I build without modifying the context manager
flow = build_flow(True)
# What I wanna do with the flow resides in main separated from what the flow consists of.
# flow.run()
flow.visualize()
Usually I implement a simple CLI inside my main()
function, so I can pick what I wanna do and build without touching anything in the code.davzucky
07/22/2021, 12:14 AMkiran
07/22/2021, 3:18 PMemre
07/22/2021, 7:13 PMkiran
07/27/2021, 7:30 PM