<@ULVA73B9P> does prefect schedule support start t...
# ask-marvin
h
@Marvin does prefect schedule support start time and end time?
m
thought for 178.7 seconds
Short answer: Not as top-level fields. In Prefect 3.x there aren’t generic `start_time`/`end_time` or `start_date`/`end_date` fields on schedules. Ways to achieve it: - RRule schedules: Use RFC 5545 parameters to bound the window -
DTSTART=
for the start -
UNTIL=
for the end Example in prefect.yaml:
Copy code
deployments:
  - name: my-deployment
    schedules:
    - rrule: "DTSTART=20240701T090000Z;RRULE:FREQ=DAILY;UNTIL=20240731T235959Z"
      timezone: "America/New_York"
For “only between certain hours each day,” you can constrain hours too:
Copy code
rrule: "RRULE:FREQ=MINUTELY;INTERVAL=5;BYHOUR=9,10,11,12,13,14,15,16"
Or via cron, restrict hours (e.g., every 5 min 9–16h, weekdays):
Copy code
cron: "*/5 9-16 * * 1-5"
- Pause/resume schedules: Use the UI or CLI to pause at a start time and resume at an end time (manually or via Automations) - Pause a specific schedule:
Copy code
prefect deployment schedule pause my-flow/my-deployment <schedule-id>
- Resume a specific schedule:
Copy code
prefect deployment schedule resume my-flow/my-deployment <schedule-id>
- Automations can be set up to pause/resume at specific timestamps. If you can share whether you need a single bounded window (between two dates) or recurring daily windows (e.g., 9am–5pm), I can give you the exact config that fits best.
h
@Marvin could prefect display next runtime via Python SDK
m
thought for 209.2 seconds
Yes—via the Python SDK you can display upcoming runtimes for a deployment by asking the API for already-scheduled flow runs. Use the next_scheduled_start_time field on returned runs. Example (async SDK, Prefect 3.x):
Copy code
import asyncio
from prefect.client import get_client

async def show_next_runs(deployment_name: str, limit: int = 10):
    async with get_client() as client:
        dep = await client.read_deployment_by_name(deployment_name)
        runs = await client.get_scheduled_flow_runs_for_deployments(
            deployment_ids=[dep.id],
            limit=limit,
        )
        print(f"Next {len(runs)} scheduled runs for {deployment_name}:")
        for r in runs:
            print(f"- {r.next_scheduled_start_time}  (run_id={r.id})")

asyncio.run(show_next_runs("my-flow/my-deployment"))
Key notes: - next_scheduled_start_time is the correct field to display the “next runtime.” - This returns runs the Prefect scheduler has already created (what you’ll also see in the UI’s “Upcoming” list). - There isn’t a public SDK method that “predicts” times directly from a schedule object; for local previews, use standard libs like croniter (cron) or dateutil.rrule (RRULE).