Adam Ivansky
06/11/2024, 9:41 PMAdam Ivansky
06/11/2024, 10:00 PMNate
06/11/2024, 10:13 PMMarvin
06/11/2024, 10:13 PMprefect.yaml
or .deploy()
method.
- Overriding Job Variables in prefect.yaml:
You can define job variables within your prefect.yaml
file under the job_variables
section. Here is an example:
yaml
deployments:
- name: demo-deployment
entrypoint: demo_project/demo_flow.py:some_work
work_pool:
name: local
job_variables:
env:
EXECUTION_ENVIRONMENT: staging
MY_NOT_SO_SECRET_CONFIG: plumbus
schedule: null
Deploy the flow with these variables using:
bash
prefect deploy -n demo-deployment
- Issues and Considerations:
- Deep vs Shallow Merge: Issues raised on GitHub suggest that job variables should use a deep merge rather than a shallow merge of dictionaries.
- Multiple Definitions: There's some confusion about precedence when environment variables are defined in multiple places (e.g., prefect.yaml
vs. work pool config).
- Character Length and Special Characters: There are known issues with character length and names containing invalid characters for Azure Container Instances.
### Useful Links
- Overriding Job Variables Guide
- GitHub Issues discussing nuances and bugs:
- Job variables should use a deep merge rather than shallow merge of dictionaries
- Invalid names being generated for Azure Container Instance runs
Should you need more details or specifics from the docs or issues, feel free to ask!Nate
06/11/2024, 10:13 PMjob_variables
dictAdam Ivansky
06/12/2024, 12:22 AMAdam Ivansky
06/12/2024, 2:10 PMMarvin
06/12/2024, 2:10 PMjob_variables
argument when using the .deploy()
method in Prefect. Here is a summary of how you can do this:
### Example Usage
You can specify job variables, including resource configurations such as CPU and memory, within your prefect.yaml
file or directly in your .deploy()
method.
#### Using prefect.yaml
yaml
deployments:
- name: demo-deployment
entrypoint: demo_project/demo_flow.py:some_work
work_pool:
name: local
job_variables:
kubernetes:
cpu: "500m"
memory: "512Mi"
schedule: null
Deploy with:
bash
prefect deploy -n demo-deployment
#### Using .deploy()
method
If you're deploying directly from code, you can pass job_variables
as a dictionary:
python
from prefect import flow
@flow
def my_flow():
# Your flow code
pass
if __name__ == "__main__":
my_flow.deploy(
name="demo-deployment",
work_pool_name="local",
job_variables={
"kubernetes": {
"cpu": "500m",
"memory": "512Mi"
}
}
)
### Helpful Links
- Overriding Job Variables Guide
This guide details how you can override job variables and includes examples for setting various configuration options, including CPU and memory for Kubernetes.
If you have further questions or need additional specifics, feel free to ask!Nate
06/12/2024, 2:11 PMcpu
and memory
are added to the variables section
you can find this in the advanced tab of your work pool in the UI
that way you can specify cpu
/ memory
whatever other value as a job variableAdam Ivansky
06/12/2024, 2:15 PMprefect_flow.from_source(
source=RemoteStorage(
url=bucket_path,
),
entrypoint="flow.py:entrypoint",
).deploy(
name=name,
job_variables=job_variables,
description=description,
tags=tags,
schedule=schedule,
build=False,
push=False,
image=os.getenv("IMAGE_URL"),
work_pool_name="work-pool-1",
parameters=parameters,
)