Preston Sharpe
11/10/2025, 6:35 PMschedule parameter of deployments depending on what environment I'm in -- ideally it would not be set for dev, stage, etc - and would be the actual cron schedule in prod. Here's a snippet of a deployment I have:
schedule:
cron: "0 7 * * *"
timezone: "America/Denver"
What would be the best way to set the schedule dynamically based on environment?Marvin
11/10/2025, 6:35 PMMarvin
11/10/2025, 6:43 PMdeploy().
import os
from prefect import schedules
ENV = os.getenv("ENVIRONMENT", "dev")
schedule = None
if ENV == "prod":
schedule = schedules.Cron("0 7 * * *", timezone="America/Denver")
(
# If you’re deploying from source (recommended)
flow.from_source(
source="<https://github.com/your-org/your-repo>",
entrypoint="path/to/flow.py:my_flow",
)
.deploy(
name=f"my-flow-{ENV}",
work_pool_name="my-pool",
schedule=schedule, # None for dev/stage, cron for prod
)
)
Option B: Keep YAML schedule-free and add the schedule only in prod via CLI
- Define the deployment without a schedule: in your prefect.yaml.
- In prod CI, add the schedule after deployment:
# Deploy (no schedule defined in YAML)
prefect deploy
# In prod only, attach a cron schedule
prefect deployment schedule create "my-flow/my-deployment" \
--cron "0 7 * * *" \
--timezone "America/Denver"
You can also pause/resume later:
prefect deployment schedule pause "my-flow/my-deployment"
prefect deployment schedule resume "my-flow/my-deployment"
Option C: Separate deployment definitions per environment
- Maintain separate deployment entries (e.g., my-deployment-dev, my-deployment-prod) and only put the schedule: on the prod one.
- In CI, select which to deploy by name pattern:
prefect deploy --name "*prod*"
# or
prefect deploy --name "*dev*"
Notes
- “No schedule” just means omit the schedule: block (or set it to null). You can still trigger ad-hoc runs via the UI/CLI.
- If you already have a YAML snippet like:
schedule:
cron: "0 7 * * *"
timezone: "America/Denver"
simply remove that block for non-prod, and use Option B to attach the schedule only in prod.
Quick question to tailor the guidance: are you deploying with prefect deploy from a prefect.yaml project, or programmatically (Python calling .deploy())? If you share that, I can provide a drop-in example for your exact setup.Preston Sharpe
11/10/2025, 8:07 PMcommand argument in my compose file looks like...
command: >
bash -c '
if [ "$environment" = "PROD" ]; then
echo "🚀 Deploying with prod deployments";
prefect --no-prompt deploy --all --prefect-file prefect_prod.yaml
else
echo "🧪 Deploying with dev deployments";
prefect --no-prompt deploy --all --prefect-file prefect_dev.yaml
fi
'
And I split my prefect.yaml file into two different files prefect_dev.yaml and prefect_prod.yaml