DiffyBron
12/11/2019, 9:30 AM#!/usr/bin/env python
import pendulum
from datetime import timedelta
from prefect import task, Flow, schedules
from prefect.schedules import filters, Schedule
@task
def say_hello():
print("hello world")
if __name__ == '__main__':
curr_schedule = Schedule(
# Fire every min
clocks=[schedules.clocks.IntervalClock(interval=timedelta(minutes=1), start_date=pendulum.datetime(2019, 1, 1, tz='America/New_York'))],
# Only on weekdays
filters=[filters.is_weekday],
# and only at 8.15am, 9.30am, 3.50pm, 4pm
or_filters=[
filters.between_times(pendulum.time(hour=8, minute=15), pendulum.time(hour=8, minute=15)),
filters.between_times(pendulum.time(hour=9, minute=30), pendulum.time(hour=9,minute=30)),
filters.between_times(pendulum.time(hour=15, minute=50), pendulum.time(hour=15,minute=50)),
filters.between_times(pendulum.time(hour=16), pendulum.time(hour=16)),
],
# do not run on Christmas
not_filters=[
filters.between_dates(12, 8, 12, 25)
]
)
with Flow('Sounds alerts', curr_schedule) as flow:
say_hello()
flow.run()
josh
12/11/2019, 3:30 PMnot_filters=[
filters.between_dates(12, 25, 12, 25)
]
DiffyBron
12/11/2019, 3:31 PMimport pendulum
from datetime import timedelta
from prefect import task, Flow, schedules
from prefect.schedules import filters, Schedule
@task
def say_hello():
print("hello world")
if __name__ == '__main__':
curr_schedule = Schedule(
# Fire every min
clocks=[schedules.clocks.IntervalClock(interval=timedelta(minutes=1), start_date=pendulum.datetime(2019, 1, 1, tz='America/New_York'))],
# Only on weekdays
filters=[filters.is_weekday],
# and only at 8.15am, 9.30am, 3.50pm, 4pm
or_filters=[
filters.between_times(pendulum.time(hour=8, minute=15), pendulum.time(hour=8, minute=15)),
filters.between_times(pendulum.time(hour=9, minute=30), pendulum.time(hour=9,minute=30)),
filters.between_times(pendulum.time(hour=15, minute=50), pendulum.time(hour=15,minute=50)),
filters.between_times(pendulum.time(hour=16), pendulum.time(hour=16)),
],
# do not run on Christmas
not_filters=[
filters.between_dates(12, 25, 12, 25)
]
)
with Flow('Sounds alerts', curr_schedule) as flow:
say_hello()
flow.run()
It's just looking at my current timezone:
[2019-12-11 15:32:39,689] INFO - prefect.Flow: Sounds alerts | Waiting for next scheduled run at 2019-12-11T15:50:00-05:00
josh
12/11/2019, 3:37 PMDiffyBron
12/11/2019, 3:37 PMcurr_schedule
earlier which could have fixed the issue.josh
12/11/2019, 3:37 PMDiffyBron
12/12/2019, 8:46 AMjosh
12/12/2019, 2:24 PMstart_date=pendulum.datetime(2019, 1, 1, tz='America/New_York')
Will give me
Waiting for next scheduled run at 2019-12-12T09:30:00-05:00
and
start_date=pendulum.datetime(2019, 1, 1, tz='Europe/Paris')
gives me
Waiting for next scheduled run at 2019-12-12T16:00:00+01:00
DiffyBron
12/12/2019, 2:32 PMjosh
12/12/2019, 2:33 PM