<@ULVA73B9P> can I create more than one cron sched...
# ask-marvin
a
@Marvin can I create more than one cron schedule for this deployment? from prefect.deployments import Deployment from test import flow from prefect.orion.schemas.schedules import CronSchedule deployment = Deployment.build_from_flow( name="TEST", flow=flow, work_queue_name="default", path='test/', schedule = CronSchedule(cron="0 1 * * *") ) deployment.apply()
m
thought for 69.5 seconds
I notice you're using the deprecated
Deployment.build_from_flow()
syntax from Prefect 2.x. Let me show you how to create multiple schedules in Prefect 3.x, which is much more straightforward:
Copy code
python
from prefect import flow
from prefect.schedules import CronSchedule

@flow
def your_flow():
    # your flow code here
    pass

if __name__ == "__main__":
    flow.deploy(
        name="TEST",
        work_queue_name="default",
        schedules=[
            CronSchedule(cron="0 1 * * *"),  # runs at 1 AM daily
            CronSchedule(cron="0 13 * * *")  # runs at 1 PM daily
        ]
    )
Key points: 1. In Prefect 3.x, we use
flow.deploy()
instead of
Deployment.build_from_flow()
2. Multiple schedules are specified using a list in the
schedules
parameter 3. Each schedule can be a different CronSchedule with its own cron expression You can also modify schedules for an existing deployment through the Prefect UI or using the REST API. For more details on scheduling options and syntax, you can refer to the Prefect documentation on creating schedules.
a
@Marvin I'm using version 2.8.0
m
thought for 30.3 seconds
For Prefect 2.8.0, you can set up multiple schedules like this:
Copy code
python
from prefect.deployments import Deployment
from prefect.orion.schemas.schedules import CronSchedule
from test import flow

deployment = Deployment.build_from_flow(
    name="TEST",
    flow=flow,
    work_queue_name="default",
    path='test/',
    schedules=[
        CronSchedule(cron="0 1 * * *"),  # runs at 1 AM daily
        CronSchedule(cron="0 13 * * *")  # runs at 1 PM daily
    ]
)

deployment.apply()
Key points: 1. Use the
schedules
parameter (plural) instead of
schedule
(singular) 2. Provide a list of
CronSchedule
objects 3. Each schedule can have its own cron expression This will create a deployment that runs according to both schedules. You can add as many schedules as you need by adding more
CronSchedule
objects to the list. You can also manage schedules through the Prefect UI after the deployment is created, where you can add, remove, or modify schedules as needed. For more information about scheduling in Prefect 2.x, you can refer to the Prefect 2.x documentation on schedules.