Praveen Gupta
01/16/2024, 10:45 AMNate
01/16/2024, 3:25 PMfrom prefect import flow
@flow(log_prints=True)
def my_flow(x: int, y: str = "Marvin", z: bool = True):
print(x, y, z)
if __name__ == "__main__":
my_flow.serve("my-first-deployment")Nate
01/16/2024, 3:26 PM.serveMarvin
01/16/2024, 3:26 PM.serve method allows you to deploy and schedule your flows with ease. Here's a concise code snippet demonstrating its usage:
python
from prefect import flow
@flow
def my_flow():
# Your flow logic here
pass
if __name__ == "__main__":
my_flow.serve(name="my_flow_deployment", interval=3600)
By executing this script, a flow named my_flow_deployment is scheduled to run every hour. It's worth noting that flows scheduled with this method run on the machine where the script is executed.
For more details, you can reference the blog post here.Praveen Gupta
01/16/2024, 3:58 PMNate
01/16/2024, 4:29 PMPraveen Gupta
01/16/2024, 4:29 PMJanet Carson
01/16/2024, 6:42 PMPraveen Gupta
01/17/2024, 6:28 AMPraveen Gupta
01/17/2024, 10:40 AMNate
01/17/2024, 3:33 PMrun_deployment in an on_completion hook likeNate
01/17/2024, 3:35 PMTimeoutError as I would expect when I run your codePraveen Gupta
01/17/2024, 4:04 PMPraveen Gupta
01/17/2024, 4:10 PMNate
01/17/2024, 4:12 PMgreetings) and then refer to my message above about using on_completion to trigger downstream work (like Salutation)Praveen Gupta
01/17/2024, 4:14 PMPraveen Gupta
01/17/2024, 4:15 PMNate
01/17/2024, 4:26 PMwait_for for flows, instead to create dependencies you have a couple options:
⢠run_deployment as I've mentioned from a state hook, or you can call it from a @task in a parent flow
@task
def run_my_deployment(**kwargs) -> FlowRun:
return run_deployment(**kwargs)
@flow
def parent(a_kw: dict, b_kw: dict):
flow_run_a = run_my_deployment(**a_kw)
run_my_deployment(**b_kw, wait_for=[flow_run_a])
⢠or put a DeploymentTrigger on the downstream flow so that it just runs when the upstream deployment sees a prefect.flow-run.Completed event (my favorite option)Praveen Gupta
01/17/2024, 4:30 PMPraveen Gupta
01/17/2024, 4:32 PMPraveen Gupta
01/17/2024, 4:32 PMPraveen Gupta
01/17/2024, 4:33 PMNate
01/17/2024, 4:34 PMPraveen Gupta
01/17/2024, 4:35 PM