<@ULVA73B9P> I have a deployment with variables on...
# ask-marvin
k
@Marvin I have a deployment with variables on a schedule. Can I use that same deployment, but pass it different variables and run it on a different schedule? Or do I need to create a separate deployment?
m
You can declare multiple deployments for different schedules and variables within the same project. This allows for reusing the same deployment logic but with different configurations and schedules. Here's a brief guide based on the relevant documents and issues: 1. Multiple Schedules in
prefect.yaml
: You can define multiple schedules for your deployments in your
prefect.yaml
file. Each deployment can have its own schedule and activation status. Example:
Copy code
deployments:
     - name: first-deployment
       schedule:
         - cron: "0 0 * * *"
           timezone: "America/Chicago"
           active: true
     - name: second-deployment
       schedule:
         - cron: "0 12 * * *"
           timezone: "America/New_York"
           active: true
Source - Prefect 2. Overriding Job Variables: You can override job variables for each specific deployment by adding a
job_variables
section to your deployment definition. Example:
Copy code
deployments:
     - name: first-deployment
       entrypoint: flow.py
       work_pool:
         name: local
       job_variables:
         env:
           VAR_1: value1
           VAR_2: value2
Source - Prefect 3. Declaring Multiple Deployments: Prefect supports declaring multiple deployments in the same
deployment.yaml
file, which lets you declare custom schedules, job variables, and deployment behaviors independently. Example:
Copy code
deployments:
     - name: first-deployment
       flow_name: count-flow
       work_pool:
         name: local

     - name: second-deployment
       flow_name: another-flow
       work_pool:
         name: local
       schedule:
         - cron: "0 12 * * *"
           timezone: "America/New_York"
You can deploy all these together or separately: - Update all deployments:
prefect deploy --all
- Update specific deployment:
prefect deploy -n first-deployment
GitHub PR - Expand Projects to Support Multiple Deployments To sum up, you don't need separate deployment projects. You can create multiple deployments within the same project, specifying different schedules and job variables using the
prefect.yaml
file.
k
@Marvin Can I use the same
entrypoint
for two or more deployments?
m
Yes, you can use the same
entrypoint
for multiple deployments. Each deployment can share the same flow code but have different configurations such as schedules, work pools, and job variables. To elaborate: 1. Using the Same Entrypoint: The
entrypoint
of a deployment refers to a function decorated as a flow within a Python file. Different deployments can reference the same entrypoint but vary in other configurations. Example:
Copy code
deployments:
     - name: deployment-1
       entrypoint: path/to/flow.py:flow_function
       schedule: 
         - cron: "0 0 * * *"
           timezone: "America/Chicago"
     - name: deployment-2
       entrypoint: path/to/flow.py:flow_function
       schedule:
         - cron: "0 12 * * *"
           timezone: "America/New_York"
2. Reusing Configuration: Prefect allows the reuse of configuration across deployments using YAML anchors and aliases. This can help maintain consistency and reduce duplication in deployment files. Example with YAML aliases:
Copy code
common_settings: &common
     entrypoint: path/to/flow.py:flow_function
     work_pool:
       name: local

   deployments:
     - name: deployment-1
       <<: *common
       schedule: 
         - cron: "0 0 * * *"
           timezone: "America/Chicago"
     - name: deployment-2
       <<: *common
       schedule:
         - cron: "0 12 * * *"
           timezone: "America/New_York"
For more detailed documentation, you can refer to the links provided: - Prefect Schedules - Deployments Guide This approach ensures that your deployments can share the same codebase while being triggered at different times or under different configurations.