Nicholas Andonakis
01/28/2024, 9:37 AMMarvin
01/28/2024, 9:37 AM.serve
method can effectively schedule your workflows. You would typically use it after defining your flow, something like this:
python
from prefect import flow
@flow
def my_flow():
# Your flow's tasks and logic here
if __name__ == "__main__":
my_flow.serve(name="my_flow_deployment", schedule=<YOUR SCHEDULE HERE>)
For scheduling your flow to run daily at 7am, you need to define a schedule object that specifies this requirement and pass it to the .serve
method. Here's an example of how you might accomplish a daily schedule at 7am:
python
from prefect import flow
from prefect.orion.schemas.schedules import IntervalSchedule
from datetime import timedelta, time
@flow
def my_flow():
# Your flow's tasks and logic here
schedule = IntervalSchedule(interval=timedelta(days=1), start_time=time(7))
if __name__ == "__main__":
my_flow.serve(name="my_daily_7am_flow", schedule=schedule)
In this snippet, the IntervalSchedule
is used to define that the interval is 1 day and the start_time is set to time(7)
, indicating 7 am. This will ensure that your flow runs every day at 7 am.
Please note that the exact syntax and available functions for scheduling may vary based on the Prefect version you are using. Always refer to the official Prefect documentation for the most accurate and up-to-date instructions.