<@ULVA73B9P> when using .deploy to setup schedules...
# marvin-in-the-wild
t
@Marvin when using .deploy to setup schedules for deployed flows to run, how can i specify what parameters to run that flow with for each different schedule / deployment? If i'm using pydantic models as inputs to the flow
m
To specify parameters for each deployment and schedule when using Pydantic models as inputs to your flow in Prefect, you can follow these general steps: 1. Specify Parameters in Deployment YAML: You can define different sets of parameters in your
prefect.yaml
file for each deployment.
Copy code
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:
Copy code
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:
Copy code
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