Hi everyone - quick question I hope. this api pag...
# ask-community
s
Hi everyone - quick question I hope. this api page seems to be down: https://docs.prefect.io/latest/api-ref/prefect/deployments/schedules.md but I'm trying to work with CronScheduler. Where do I import CronScheduler from? prefect.clients.schema or prefect.deployments.schedules?
j
Thanks for the heads up. Will look into the page. If you just want to create a cron schedule with a
flow.deploy
or
flow.serve
created deployment you can do the following as shown in the QuickStart:
Copy code
from prefect import flow

if __name__ == "__main__":
    flow.from_source(
        source="<https://github.com/discdiver/demos.git>",
        entrypoint="my_gh_workflow.py:repo_info",
    ).deploy(
        name="my-first-deployment",
        work_pool_name="my-managed-pool",
        cron="0 1 * * *",
    )
If you need the CronSchedule object for more fine-grained control you can do this:
Copy code
from prefect import flow
from prefect.server.schemas.schedules import CronSchedule

if __name__ == "__main__":
    flow.from_source(
        source="<https://github.com/discdiver/demos.git>",
        entrypoint="my_gh_workflow.py:repo_info",
    ).deploy(
        name="my-first-deployment",
        work_pool_name="my-managed-pool",
        schedule=(CronSchedule(cron="0 0 * * *", timezone="America/Chicago")),
    )
n
the import in that second example is incorrect, you should import from client schemas - will PR a fix
Copy code
from prefect.client.schemas.schedules import CronSchedule
s
Thanks so much - was looking for the second method! I'm assuming deployments.schedules is for the first use ?
n
anywhere you provide a
CronSchedule
object you should be able to use this import
Copy code
from prefect.client.schemas.schedules import CronSchedule
j
Here are API docs for prefect.client.schemas.schedule.CronSchedule. PRs for those fixes are up. Thanks for raising!