merlin
02/20/2025, 8:28 PMprefect deploy
to upload my deployment from prefect.yaml. How can I configure the prefect.yaml to set schedules to active: true
conditional on an environment variable or other factor. I tried using the output of of a run_shell_script step with "{{ true-if-script-output-is-prod.stdout }}"
, but prefect is not parsing it as true
.
1 validation error for DeploymentScheduleCreate
active
Input should be a valid boolean, unable to interpret input
Marvin
02/20/2025, 8:28 PMactive
status of a schedule in prefect.yaml
using an environment variable or a script output. Unfortunately, Prefect's YAML configuration does not support conditional logic or template rendering for boolean values like active
. The error you're seeing is because the value "{{ true-if-script-output-is-prod.stdout }}"
is not being interpreted as a valid boolean.
To achieve dynamic configuration, you might consider:
1. Pre-processing the YAML: Use a script to modify the prefect.yaml
before running prefect deploy
. This script can check your environment variable or script output and set the active
field accordingly.
2. Use Python for Deployment: Instead of relying solely on prefect.yaml
, you can programmatically create and deploy your flow using Python. This allows you to use Python's logic to determine if the schedule should be active based on an environment variable.
Here's a simple example of how you might do this in Python:
python
from prefect import flow
from prefect.deployments import Deployment
import os
@flow
def my_flow():
print("Running my flow")
# Determine if the schedule should be active
is_prod = os.getenv("ENV") == "prod"
deployment = Deployment.build_from_flow(
flow=my_flow,
name="My Deployment",
schedule={"cron": "0 * * * *", "active": is_prod}
)
deployment.apply()
This approach circumvents the limitations of YAML by using Python for more complex logic.
For more details on how Prefect handles schedules and deployments, you can refer to the Prefect documentation on schedules and deployment configuration.