S K
04/13/2021, 4:57 AMHello, I want to schedule a flow all 7 days a week, but on weekend want to reduce the run frequency to every 4 hours once instead of every one hour. This is the pice of code for all 7 days week to run every 1 hr from 6 am to 6 pm which needs modification for weekend schedule. schedule = Schedule(
# emit an event every hour
clocks=[
IntervalClock(
start_date=pendulum.datetime(2021, 4, 1, tz="America/Los_Angeles"),
interval=timedelta(hours=1))
],
# only include weekdays
#filters=[filters.is_weekday],
# only include 6am and 6pm
filters=[
filters.between_times(time(6), time(18))
# filters.between_times(time(6), time(18))
]
)
nicholas
from prefect.schedules.clocks import CronClock
week = CronClock(cron="0 6-18 * * 1-5")
weekend = CronClock(cron="0 6-18/4 * * 0,6")
clocks = [week, weekend]
This creates 2 distinct clocks (so you can modify them as you see fit), 1 for weekdays and 1 for the weekend. The first clock runs on the 0th minute of every hour, from Monday - Friday (1-5
) and the second clock runs on the 0th minute of every 4th hour (*/4
) on Saturday and Sunday (0,6
)