Tom Matthews
05/21/2024, 6:29 PMMarvin
05/21/2024, 6:29 PMprefect.yaml
file for each deployment.
yaml
deployments:
- name: my_first_deployment
schedule:
cron: "0 0 * * *"
parameters:
pydantic_model_param:
field1: value1
field2: value2
- name: my_second_deployment
schedule:
cron: "0 12 * * *"
parameters:
pydantic_model_param:
field1: value3
field2: value4
2. Using Pydantic Models in Your Flow:
python
from prefect import flow
from pydantic import BaseModel
class MyParams(BaseModel):
field1: str
field2: str
@flow(name="My Flow")
def my_flow(params: MyParams):
print(f"Running with parameters: {params}")
3. Build and Apply Deployments:
python
from prefect.deployments import Deployment
from prefect.server.schemas.schedules import CronSchedule
def build_deployment():
dep1 = Deployment.build_from_flow(
flow=my_flow,
name="my_first_deployment",
schedule=(CronSchedule(cron="0 0 * * *")),
parameters={"params": MyParams(field1="value1", field2="value2").dict()}
)
dep2 = Deployment.build_from_flow(
flow=my_flow,
name="my_second_deployment",
schedule=(CronSchedule(cron="0 12 * * *")),
parameters={"params": MyParams(field1="value3", field2="value4").dict()}
)
dep1.apply()
dep2.apply()
This should allow you to create multiple deployments with different schedules and parameters.
- For handling Pydantic models specifically, see the Prefect Docs on Parameters.
- Issues related to serialization: Prefect uses orjson
for speed, but orjson
has limitations. If you face issues with complex Pydantic models, check GitHub Issue 9536.
For detailed information, please refer to:
- Prefect Schedules Documentation
- Creating Deployments