Tom Matthews
05/24/2024, 4:24 PMMarvin
05/24/2024, 4:24 PMschedule argument to the Deployment.build_from_flow method. For example:
python
from prefect.server.schemas.schedules import CronSchedule
cron_demo = Deployment.build_from_flow(
pipeline,
"etl",
schedule=(CronSchedule(cron="0 0 * * *", timezone="America/Chicago"))
)
2. Using the prefect deploy Command:
If you are using worker-based deployments, you can specify schedules through the interactive prefect deploy command. This will prompt you to choose which type of schedule to create.
3. Modifying the prefect.yaml File:
You can add multiple schedules directly in the schedules section of the prefect.yaml file. Here's an example:
yaml
deployments:
...
schedules:
- cron: "0 0 * * *"
timezone: "America/Chicago"
active: false
- cron: "0 12 * * *"
timezone: "America/New_York"
active: true
- cron: "0 18 * * *"
timezone: "Europe/London"
active: true
You can find more information in the Prefect documentation on schedules.
Additionally, you can refer to this GitHub search result for discussions on similar topics.Tom Matthews
05/24/2024, 4:25 PManimal how would i set one of the crons to run with the animal="dog" and the other cron to run with animal="cat"?Marvin
05/24/2024, 4:26 PMprefect.yaml file for each schedule. Here's how you might do it for your example with animal as a parameter:
yaml
deployments:
- name: my_deployment
flow_name: my_flow
parameters:
animal: "default_value"
schedules:
- cron: "0 0 * * *"
timezone: "America/Chicago"
parameters:
animal: "dog"
- cron: "0 12 * * *"
timezone: "America/New_York"
parameters:
animal: "cat"
In the example above:
- The deployment my_deployment has two schedules.
- The first schedule, running at midnight Chicago time, sets animal to "dog".
- The second schedule, running at noon New York time, sets animal to "cat".
Each schedule can have its own set of parameters defined under the parameters key. This allows you to set different values for each run triggered by different schedules.
You can find more guidance in the Prefect documentation on schedules and deployments.Tom Matthews
05/24/2024, 4:28 PMMarvin
05/24/2024, 4:29 PMprefect.yaml file.
However, you can achieve similar behavior by creating multiple deployments for the same flow, each with its own schedule and set of parameters. Here is an example:
yaml
deployments:
- name: my_deployment_dog
flow_name: my_flow
parameters:
animal: "dog"
schedules:
- cron: "0 0 * * *"
timezone: "America/Chicago"
- name: my_deployment_cat
flow_name: my_flow
parameters:
animal: "cat"
schedules:
- cron: "0 12 * * *"
timezone: "America/New_York"
In this example:
- my_deployment_dog runs with the parameter animal set to "dog" at the specified cron schedule.
- my_deployment_cat runs with the parameter animal set to "cat" at a different cron schedule.
Creating separate deployments each with its own parameters and schedules aligns with the recommended approach for handling such cases in Prefect.
For further details, you can review the Prefect documentation or check out related discussions and issues on their GitHub repository.
I apologize for any confusion earlier.Kevin Grismore
05/24/2024, 4:32 PMTom Matthews
05/24/2024, 4:34 PMKevin Grismore
05/24/2024, 4:35 PMTom Matthews
05/24/2024, 4:35 PM