<@ULVA73B9P> I have a flow that takes a parameter,...
# ask-marvin
b
@Marvin I have a flow that takes a parameter, I use the
prefect.yaml
file to define multiple deployments that each execute this flow with different parameters. E.g.
Copy code
deployments:
- name: 'My flow (foo)'
  entrypoint: src/flows.py:my_flow
  parameters: 
    data: foo
  work_pool:
    name: default
    work_queue_name: default
  version:
  concurrency_limit:
  schedules:
  - cron: 0 11,23 * * *
    timezone:
    day_or: true
    active: true
- name: 'My flow (bar)'
  entrypoint: src/flows.py:my_flow
  parameters: 
    data: bar
  work_pool:
    name: default
    work_queue_name: default
  version:
  concurrency_limit:
  schedules:
  - cron: 0 10,22 * * *
    timezone:
    day_or: true
    active: true
As you can see, I have copy and pasted the deployment config 2 times and only changed the parameter and cron schedule. Instead of copying and pasting this deployment config multiple times, is there a way to define 1 dynamic deployment that can have have different params and different cron schedules?
m
thought for 165.2 seconds
Yes — in Prefect 3.x you can use a single deployment with multiple schedules, and each schedule can supply its own parameters. That lets you avoid duplicating the deployment just to change
parameters
and
cron
. Here’s your example rewritten as one deployment with two schedules, each overriding the
data
parameter and using its own cron:
Copy code
deployments:
- name: "My flow"
  entrypoint: src/flows.py:my_flow
  # Optional defaults applied when a schedule doesn't override
  parameters:
    data: null
  work_pool:
    name: default
    work_queue_name: default
  version:
  concurrency_limit:
  schedules:
    - slug: "foo-schedule"
      cron: "0 11,23 * * *"
      day_or: true
      active: true
      parameters:
        data: foo
    - slug: "bar-schedule"
      cron: "0 10,22 * * *"
      day_or: true
      active: true
      parameters:
        data: bar
Notes: - The
parameters
under each schedule override the deployment-level
parameters
for runs triggered by that schedule. -
slug
is optional but helpful for identifying schedules later. - Keep separate deployments only if you also need different work pools/queues, infra, tags, etc. If it’s just params and timing, multiple schedules in one deployment is the simplest option. If you’d like, I can also show a variant with YAML anchors to DRY up shared fields.