Kaleb King
07/15/2024, 7:32 PMMarvin
07/15/2024, 7:32 PMprefect.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:
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:
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:
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.Kaleb King
07/15/2024, 7:40 PMentrypoint
for two or more deployments?Marvin
07/15/2024, 7:41 PMentrypoint
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:
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:
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.