Jackson Nguyen
02/21/2025, 9:13 PMMarvin
02/21/2025, 9:13 PMjob_variables
argument in the .deploy()
method. These variables can be accessed in your flow runs and are visible under the Configuration tab in the Prefect UI. You can override them when running flows via the UI, CLI, or automations.
Here's a concise approach to setting and accessing job variables:
1. Set Job Variables:
- Define them in your deployment using the job_variables
argument when deploying your flow.
2. Access Job Variables:
- You can access these variables in your flow using the Prefect runtime API, which allows you to retrieve configuration and context dynamically during a flow run.
For more detailed steps and examples, refer to the Prefect documentation on customizing deployments.
If you were thinking about using environment variables, that's certainly a common approach, but Prefect's job variables provide a more integrated way to manage such configurations within the Prefect ecosystem.Nate
02/21/2025, 9:14 PMJackson Nguyen
02/21/2025, 9:22 PM[a,b]
. I want to do some prechecks so that I never supply a
and b
at the same time. I can make a function to do this, and call it at the start of every flow, but I find that a bit ugly? for lack of a better term.
Instead, I thought I could create a common flow X that is run before any other flow, and use X as the deployed flow that will call my true flow. The environment variable Y would be changed per deployments, so that X will call that flow Y after performing the prechecks.Jackson Nguyen
02/21/2025, 9:23 PMNate
02/21/2025, 9:27 PMI intend to create many deployments/flows that all have a common set of parameters that are supplied to them. Let's say,might be lacking context, this sounds like some pydantic model. I want to do some prechecks so that I never supply[a,b]
anda
at the same time. I can make a function to do this, and call it at the start of every flow, but I find that a bit ugly? for lack of a better term.b
class Params(BaseModel):
a: int | None = None
b: str | None = None
@model_validator
def assert_xor(self):
if self.a and self.b:
raise ValueError("dont do that")
return self
@flow
def foo(params: Params): ...
Jackson Nguyen
02/21/2025, 9:38 PMa
and b
show up as individual parameters?Nate
02/21/2025, 9:40 PMNate
02/21/2025, 9:40 PMNate
02/21/2025, 9:41 PMJackson Nguyen
02/21/2025, 9:44 PMNate
02/21/2025, 9:45 PMstr
field as wellJackson Nguyen
02/21/2025, 9:45 PMJackson Nguyen
02/21/2025, 9:45 PMNate
02/21/2025, 9:45 PM