<@ULVA73B9P> is there a way to specify multiple di...
# marvin-in-the-wild
t
@Marvin is there a way to specify multiple different parameterised deployment schedules? by that i mean saying run X deployment with Y cron and some flow parameters, and again on Z cron with different parameters?
m
Yes, you can specify multiple parameterized deployment schedules in Prefect. There are various ways to achieve this: 1. Using Python Deployment Files: You can create schedules by passing a
schedule
argument to the
Deployment.build_from_flow
method. For example:
Copy code
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:
Copy code
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.
t
@Marvin yes but say my flow accepts one an argument:
animal
how would i set one of the crons to run with the
animal="dog"
and the other cron to run with
animal="cat"
?
m
To set different parameters for different schedules in a deployment, you can specify the parameters in the
prefect.yaml
file for each schedule. Here's how you might do it for your example with
animal
as a parameter:
Copy code
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.
t
@Marvin i think you might be lying to me are you sure? I can't see any documentation or the source code supporting this ability to specify parameters like this?
m
It appears I misspoke earlier. According to the available documentation and discussions in related Prefect GitHub issues, it is currently not supported to specify different parameters for different schedules within the same deployment using the
prefect.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:
Copy code
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.
k
yeah you can't assign different params to different schedules on a single deployment, it's still one set of default params per deployment for now. definitely something we've thought about though
t
Thanks Kevin, i'd love this as a feature - i think it makes a lot of sense to have it! At the moment to workaround i just deploy a different versions of the same flow with the default values i want and set a cron schedule for those. Do you have any recommendations for a better way / best practices?
k
that strategy makes the most sense to me based on how deployments work right now
t
Cool, thanks 👍