Mark
09/26/2024, 8:35 AMMarvin
09/26/2024, 8:36 AMdeployment.yaml
file with the schedule and parameters defined. Here is a basic example:
yaml
name: my-deployment
flow_name: my_flow
parameters:
param1: value1
param2: value2
schedules:
- cron: "0 0 * * 0" # Weekly on Sundays at midnight
timezone: "UTC"
- cron: "0 12 * * 0" # Weekly on Sundays at noon
timezone: "UTC"
tags: []
This YAML file defines two cron schedules which trigger the flow weekly at different times on Sunday.
### For Prefect 3.x
Similarly, you can define the schedule and parameters in a YAML file. Here is an example:
yaml
name: my-deployment
flow_name: my_flow
parameters:
param1: value1
param2: value2
schedules:
- interval: "weekly"
cron: "0 0 * * 0" # Weekly on Sundays at midnight
timezone: "UTC"
- interval: "weekly"
cron: "0 12 * * 0" # Weekly on Sundays at noon
timezone: "UTC"
tags: []
### Adding the Schedule Programmatically in Prefect 3.x
You can also create the schedule programmatically:
python
from datetime import timedelta, datetime
from prefect.client.schemas.schedules import IntervalSchedule
from your_flow_module import my_flow
schedule = IntervalSchedule(
interval=timedelta(weeks=1),
anchor_date=datetime(2023, 1, 1, 0, 0),
timezone="UTC"
)
deployment = my_flow.serve(
name="my-deployment",
schedule=schedule,
parameters={"param1": "value1", "param2": "value2"}
)
In both versions, make sure you apply the deployment using the Prefect CLI or UI accordingly.
References:
- Prefect 2.x scheduling: Schedules in Prefect 2.x
- Prefect 3.x scheduling: Schedules in Prefect 3.x
Let me know if you need further assistance!Mark
09/26/2024, 8:37 AMMark
09/26/2024, 8:38 AMMarvin
09/26/2024, 8:39 AMyaml
# deployment_1.yaml
name: my-deployment-1
flow_name: my_flow
parameters:
param1: value1_set1
param2: value2_set1
schedules:
- cron: "0 0 * * 0" # Weekly on Sundays at midnight
timezone: "UTC"
tags: []
# deployment_2.yaml
name: my-deployment-2
flow_name: my_flow
parameters:
param1: value1_set2
param2: value2_set2
schedules:
- cron: "0 12 * * 0" # Weekly on Sundays at noon
timezone: "UTC"
tags: []
Apply these deployments using the Prefect CLI:
prefect deployment apply deployment_1.yaml
prefect deployment apply deployment_2.yaml
### For Prefect 3.x
Similar to Prefect 2.x, you can define multiple deployments with different schedules and parameters in YAML:
yaml
# deployment_1.yaml
name: my-deployment-1
flow_name: my_flow
parameters:
param1: value1_set1
param2: value2_set1
schedules:
- interval: "weekly"
cron: "0 0 * * 0" # Weekly on Sundays at midnight
timezone: "UTC"
tags: []
# deployment_2.yaml
name: my-deployment-2
flow_name: my_flow
parameters:
param1: value1_set2
param2: value2_set2
schedules:
- interval: "weekly"
cron: "0 12 * * 0" # Weekly on Sundays at noon
timezone: "UTC"
tags: []
Apply these deployments using the Prefect CLI:
prefect deployment apply deployment_1.yaml
prefect deployment apply deployment_2.yaml
### References
- Prefect 2.x scheduling: Schedules in Prefect 2.x
- Prefect 3.x scheduling: Schedules in Prefect 3.x
Let me know if you need any further assistance!Mark
09/26/2024, 8:39 AMMarvin
09/26/2024, 8:40 AMyaml
name: my-deployment
flow_name: my_flow
schedules:
- cron: "0 0 * * 0" # Weekly on Sundays at midnight
timezone: "UTC"
parameters:
param1: value1_set1
param2: value2_set1
- cron: "0 12 * * 0" # Weekly on Sundays at noon
timezone: "UTC"
parameters:
param1: value1_set2
param2: value2_set2
tags: []
Here, the deployment schedules the flow to run at two different times on Sundays, each with its own set of parameters.
### Prefect 3.x Example
In Prefect 3.x, you can similarly define multiple schedules with different parameters within a single deployment YAML file.
yaml
name: my-deployment
flow_name: my_flow
schedules:
- cron: "0 0 * * 0" # Weekly on Sundays at midnight
timezone: "UTC"
parameters:
param1: value1_set1
param2: value2_set1
- cron: "0 12 * * 0" # Weekly on Sundays at noon
timezone: "UTC"
parameters:
param1: value1_set2
param2: value2_set2
tags: []
This configuration specifies that the flow should run at two different times on Sundays, each with distinct parameter values.
### Setting Up in the UI or CLI
For more detailed control or if additional customization is needed, you might want to set up the schedules and parameters through the Prefect UI or using the Prefect CLI.
#### Prefect UI
In the Prefect UI, you can create and configure multiple schedules within a single deployment, including setting different parameters for each schedule.
#### Prefect CLI
You can also use the Prefect CLI to create and configure deployments. Use commands to create and update deployments with different schedules and parameters.
### References:
- Prefect 2.x documentation on Schedules and Parameters
- Prefect 3.x documentation on Scheduling and Parameters
Feel free to ask if you need more detailed examples or further assistance!Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by