Does Prefect 2.0 support filters and adjustments e.g. to restrict the schedule to only run during business hours?

Not directly. Filters and Adjustments have been replaced by RRules Schedule, which includes the same functionality and a lot more by using the ical standard (anything you can do in a calendar app).

See docs here:

You can either provide RRules strings or use the rrules package to build the rules in code:

:point_right: Note that: It is anticipated that the UI will be the primary interface for scheduling to make it easier and more flexible for users to define or adjust schedules without having to redeploy any code.

Example - hourly schedule during business hours

Prefect 1.0

Here is an example to schedule your flow to run hourly but only during business days from 9 to 5:

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

# respects DST
clock = IntervalClock(
    start_date=pendulum.datetime(2021, 11, 12, 9, 0, tz="Europe/London"),
schedule = Schedule(clocks=[clock],
                    filters=[is_weekday, between_times(time(9), time(17))])

for sched in

Prefect 2.0

Prefect 2.0 doesn’t require custom filters or adjustments as it relies on rrule for complex scheduling. This makes it easier, as you can create and validate this schedule without Prefect!

import pendulum
from dateutil.rrule import rrule, MO, TU, WE, TH, FR, HOURLY

bus_hours = rrule(
    freq=HOURLY, interval=1,
    dtstart=pendulum.datetime(2022, 9, 29, 18, 0),
    byweekday=(MO, TU, WE, TH, FR),
    count=20,  # add limit count for testing schedules - todo remove later
    byhour=list(range(9, 18))
for sched_date in bus_hours:

Once you have validated that your schedule is working as intended, you may add that to your deployment as follows.

Generate rrule string:


Rrule string generated from the command above:


which you can pass to deployment CLI:

prefect deployment build -n prod --rrule 'DTSTART:20220929T180000\nRRULE:FREQ=HOURLY;COUNT=20;BYDAY=MO,TU,WE,TH,FR;BYHOUR=9,10,11,12,13,14,15,16,17'

For more rrule examples, check this documentation page:

Further resources

So just to be clear, in Prefect 1 you could have an IntervalSchedule with a start and end date, but in Prefect 2 you can’t.

So the replacement for Prefect 1’s IntervalSchedule in Prefect 2 is not IntervalSchedule (which still exists but no longer supports start and end dates), but actually RRule.

Is that correct?