Hristo Mavrodiev
09/27/2025, 3:43 PMMarvin
09/27/2025, 3:43 PMMarvin
09/27/2025, 3:49 PMfrom prefect import flow
@flow
def my_flow():
print("hello from cron")
my_flow.deploy(
name="hourly",
work_pool_name="my-pool",
cron="0 * * * *", # top of every hour, UTC by default
)
- With timezone or advanced control: use a Schedule via prefect.schedules.Cron
from prefect import flow
from prefect.schedules import Cron
@flow
def my_flow():
print("hello from cron")
my_flow.deploy(
name="hourly-nyc",
work_pool_name="my-pool",
schedule=Cron("0 * * * *", timezone="America/New_York"),
)
- From source (e.g., repo/project) with a Cron schedule
from prefect.flows import Flow
from prefect.schedules import Cron
Flow.from_source(
".", # or a git URL / storage
"flows/my_flow.py:my_flow",
).deploy(
name="hourly-utc",
work_pool_name="my-pool",
schedules=[Cron("0 * * * *", timezone="UTC")],
)
CLI
- One-shot deploy with a cron schedule and timezone
prefect deploy ./flows/my_flow.py:my_flow -n hourly-nyc --work-pool my-pool --cron "0 * * * *" --timezone "America/New_York"
- Or, deploy first, then add a schedule to an existing deployment
# Create deployment
prefect deploy ./flows/my_flow.py:my_flow -n hourly --work-pool my-pool
# Attach cron schedule
prefect deployment schedule create "my_flow/hourly" --cron "0 * * * *" --timezone "America/New_York"
Make sure a worker is running
- A deployment won’t run unless a worker is polling the work pool.
# Create a local (process) work pool if you don’t have one
prefect work-pool create "my-pool" --type process
# Start a worker to poll the pool
prefect worker start --pool my-pool
Cron and timezone notes
- Prefect uses standard 5-field cron (minute hour day-of-month month day-of-week), via croniter.
- Use IANA timezones like America/New_York or Europe/Berlin for DST-aware schedules.
- The Cron constructor supports day_or
if you need to control how day-of-month and day-of-week interact (defaults to OR).
Docs
- Create schedules: Create schedules
- API reference (schedules): prefect.schedules API
- Manage deployment schedules via CLI: run prefect deployment schedule create --help
If you can share your desired schedule expression and timezone, I can tailor the exact commands/snippet for your setup.