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:
https://dateutil.readthedocs.io/en/stable/rrule.html
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"),
interval=timedelta(hours=1),
)
schedule = Schedule(clocks=[clock],
filters=[is_weekday, between_times(time(9), time(17))])
for sched in schedule.next(20):
print(sched)
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:
print(sched_date)
Once you have validated that your schedule is working as intended, you may add that to your deployment as follows.
Generate rrule string:
bus_hours.__str__()
Rrule string generated from the command above:
'DTSTART:20220929T180000\nRRULE:FREQ=HOURLY;COUNT=20;BYDAY=MO,TU,WE,TH,FR;BYHOUR=9,10,11,12,13,14,15,16,17'
which you can pass to deployment CLI:
prefect deployment build your_flow.py:your_flow_fun -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:
https://dateutil.readthedocs.io/en/stable/rrule.html#rrule-examples