<@ULVA73B9P> How to use .deploy() and include sche...
# ask-marvin
e
@Marvin How to use .deploy() and include schedules using Prefect 3
m
To use the
.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.
n
tldr
.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 instead
e
What is the object that
schedules
takes? I keep getting the error:
unexpected keyword argument 'cron'
n
can you show what you're trying?
it should be like this
e
The below:
Copy code
flow.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}]
n
I would do it like the docs example (or this one) and using
CronSchedule
Copy code
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?
e
Thank you! I just moved from Prefect 2 to 3 this morning and was having issues changing the syntax and other differences!
It worked
n
cool! if there's a specific thing that tripped you up please let me know and I can add it here to the common gotchas associated with upgrading
e
Yes, I think the difference in how schedules are assigned in 2 vs 3 is the one big one that I had an issue with.
n
just so I'm sure I understand you're talking about this difference? from
Copy code
schedules=[{'cron': '0 * * * *', 'timezone': 'America/Chicago', 'active': True}]
to
Copy code
schedules=[CronSchedule(cron="0 14 * * *", timezone="America/Chicago")]
or was there something else?
e
I believe that in 2 the parameter is
schedule
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.
n
aha! good callout, yes in 2.x it was originally
schedule
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!
👍 1