Erik Forsman
10/24/2024, 6:24 PMMarvin
10/24/2024, 6:25 PM.deploy()
method in Prefect 3 and include schedules with it, you need to understand the updated mechanisms in Prefect 3 for managing deployments and schedules. Here's a summary based on the latest documentation:
1. Deployment and Scheduling Overview:
- In Prefect 3, you can specify schedules for flows, allowing automatic creation of flow runs based on defined schedules.
- You can add one or more schedules to any deployed flow. This can be done through various methods:
- Prefect UI
- Prefect CLI (prefect deployment schedule
command)
- Configuration file (prefect.yaml
)
2. Creating Schedules:
- Schedules can be created using options like cron, interval, or RRULE when defining your deployment.
- You can define a schedule when you use flow.deploy
or through the interactive prefect deploy
command.
3. Implementing Schedules in Deployment:
- If using the Prefect UI, simply specify the desired schedule details such as cron or interval strings.
- For a more programmatic approach, when setting up your deployment, use the schedules
field to specify the timing mechanism for flow execution.
For a deeper dive and examples, you can refer to the Prefect 3 documentation on adding schedules and deploying flows. These resources will provide you with the details needed to effectively schedule your deployments in Prefect 3.Nate
10/24/2024, 6:29 PM.deploy()
accepts a a list schedules
where you can pass interval schedules or whatever else type of schedule
if you're using deploy(*manydeployments)
then the <http://some_flow.to|some_flow.to>_deployment()
method should accept it insteadErik Forsman
10/24/2024, 6:30 PMschedules
takes? I keep getting the error: unexpected keyword argument 'cron'
Nate
10/24/2024, 6:30 PMNate
10/24/2024, 6:31 PMErik Forsman
10/24/2024, 6:33 PMflow.from_source(
source=github_repo,
entrypoint=d["entrypoint"],
).deploy(
name=deployment_name,
work_pool_name=work_pool_name,
work_queue_name=d["worker_info"]["worker_queue"],
parameters=d["parameters"],
schedules=schedules,
job_variables={"env": {"ENVIRONMENT": environment}},
)
Where schedules
is [{'cron': '0 * * * *', 'timezone': 'America/Chicago', 'active': True}]
Nate
10/24/2024, 6:40 PMCronSchedule
if __name__ == "__main__":
flow.from_source(
source="<https://github.com/zzstoatzz/prefect-monorepo.git>",
entrypoint="src/demo_project/daily_flow.py:daily_flow",
).deploy(
name="My Daily Flow Deployment",
schedules=[CronSchedule(cron="0 14 * * *", timezone="America/Chicago")],
work_pool_name="local",
)
where that import is from prefect.client.schemas.schedules import CronSchedule
did you find that dictionary syntax somewhere in the prefect docs?Erik Forsman
10/24/2024, 6:51 PMErik Forsman
10/24/2024, 6:51 PMNate
10/24/2024, 6:53 PMErik Forsman
10/24/2024, 6:54 PMNate
10/24/2024, 6:55 PMschedules=[{'cron': '0 * * * *', 'timezone': 'America/Chicago', 'active': True}]
to
schedules=[CronSchedule(cron="0 14 * * *", timezone="America/Chicago")]
or was there something else?Erik Forsman
10/24/2024, 6:56 PMschedule
vs 3 it is schedules
which is another gotcha. Unless that was a change before 3? Although I don't remember using schedules in plural in my 2 implementations.Nate
10/24/2024, 6:58 PMschedule
and then we allowed either singular or plural to allow many schedules for one deployment and now its just schedules
(although honestly we should simply cast schedule
to schedules
if its provided) I will get that added there - thank you!