https://prefect.io logo
Title
j

Jeff Kehler

05/06/2022, 6:40 AM
I have a question with the
IntervalClock
scheduler. If i were to pass
interval=timedelta(hours=1)
to schedule a run for every hour, would this be scheduled to occur at the beginning of every hour? Or would it be relative to when I register the Flow? eg if I register the flow at 1:13pm then the
IntervalClock
would trigger at 13 minutes past the hour every hour? Or would it just kick off at the first minute of every hour?
a

Anna Geller

05/06/2022, 9:42 AM
it would be relative to the start date you set, e,g.
from datetime import time, timedelta
import pendulum
from prefect.schedules import Schedule
from prefect.schedules.clocks import IntervalClock
from prefect.schedules.filters import between_times, is_weekday

clock = IntervalClock(
    start_date=pendulum.datetime(2022, 5, 12, 9, 0, tz="Europe/London"),
    interval=timedelta(hours=1),
)
schedule = Schedule(clocks=[clock])

for sched in schedule.next(20):
    print(sched)
If you want to make it less verbose, this CRON will have the effect you want - every day at 9:
from prefect.schedules import CronSchedule


schedule = CronSchedule(
    cron="0 9 * * *"
)
but you can also pass a start date here:
from prefect.schedules import CronSchedule


schedule = CronSchedule(
    cron="0 9 * * *", start_date=pendulum.datetime(2022, 1, 12, 0, 0, tz="America/New_York")
)