def test_create_schedule_adjustments(): # jan 3 was a thursday dt = pendulum.datetime(2019, 1, 3) s = schedules.Schedule( # fire every hour clocks=[clocks.IntervalClock(timedelta(hours=1))], # only on weekdays filters=[filters.is_weekday], # only at 9am or 3pm or_filters=[ filters.between_times(pendulum.time(9), pendulum.time(9)), filters.between_times(pendulum.time(15), pendulum.time(15)), ], # not on january 8 not_filters=[filters.between_dates(1, 8, 1, 8)], # add three hours adjustments=[adjustments.add(timedelta(hours=3))], ) assert s.next(8, after=dt) == [ dt.replace(hour=12), dt.replace(hour=18), dt.add(days=1).replace(hour=12), dt.add(days=1).replace(hour=18), # skip weekend dt.add(days=4).replace(hour=12), dt.add(days=4).replace(hour=18), # skip jan 8! dt.add(days=6).replace(hour=12), dt.add(days=6).replace(hour=18), ]
def test_create_schedule_multiple_exclusive_filters(): dt = pendulum.datetime(2019, 1, 1) s = schedules.Schedule( clocks=[clocks.IntervalClock(timedelta(hours=1))], filters=[ filters.between_times(pendulum.time(9), pendulum.time(10)), filters.between_times(pendulum.time(15), pendulum.time(16)), ], ) assert s.next(6, after=dt) == []
def test_create_schedule_or_filters(): dt = pendulum.datetime(2019, 1, 1) s = schedules.Schedule( clocks=[clocks.IntervalClock(timedelta(hours=1))], or_filters=[ filters.between_times(pendulum.time(9), pendulum.time(9)), filters.between_times(pendulum.time(15), pendulum.time(15)), ], ) assert s.next(6, after=dt) == [ dt.add(days=0).replace(hour=9), dt.add(days=0).replace(hour=15), dt.add(days=1).replace(hour=9), dt.add(days=1).replace(hour=15), dt.add(days=2).replace(hour=9), dt.add(days=2).replace(hour=15), ]
payment_list.append(payment_temp) return sorted(payment_list, key=itemgetter("payment"), reverse=True) class LogResult(Task): def run(self, res): return self.logger.info(pprint.pprint(res)) schedule = Schedule( clocks=[ IntervalClock(interval=timedelta(weeks=1), start_date=datetime.utcnow()) ], filters=[between_times(time(hour=10), time(hour=23))], ) with Flow(name="Loan Payoff Reminder", schedule=schedule) as flow: budget = Parameter("budget", default=3000) phone_number = Parameter("phone_number", default="+15707306535") # Google Parameters scopes = Parameter( "SCOPES", default=["https://www.googleapis.com/auth/spreadsheets"]) spreadsheet_id = Parameter( "SPREADHSEET_ID", default="1Wb5Anty3nvaa0jHY7NEYz7i6jyIOQ5Q9z2GLqmLjmPA") project_id = Parameter("project_id", default="flows-270323") auth_provider_x509_cert_url = Parameter( "auth_provider_x509_cert_url", default="https://www.googleapis.com/oauth2/v1/certs",
def test_between_times(test_times): dt = pendulum.datetime(2019, 6, 1, 6) filter_fn = filters.between_times(test_times[0], test_times[1]) assert filter_fn(dt) is test_times[2]
@task(name="Relógio", log_stdout=True) def imprimir_agendamento(alterado: bool = False): print(f"Essa execução ocorre a cada {4 if alterado else 13} minutos") relogio_padrao = IntervalClock( start_date=pendulum.datetime(2021, 5, 27, 19, 30, tz="America/Sao_Paulo"), interval=timedelta(minutes=11), ) relogio_alterado = IntervalClock( start_date=pendulum.datetime(2021, 5, 27, 19, 30, tz="America/Sao_Paulo"), interval=timedelta(minutes=3), parameter_defaults={"Alterado": True}, ) agendamento = Schedule( clocks=[relogio_padrao, relogio_alterado], filters=[is_weekday, between_times(pendulum.time(19), pendulum.time(23))], ) with Flow("agendamento-avançado", schedule=agendamento) as flow: alterado = Parameter("Alterado", default=False, required=False) imprimir_agendamento(alterado) if __name__ == "__main__": flow.register(project_name="extras")
@task def say_hello(): print("hello world") 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=10, minute=37), pendulum.time(hour=10, minute=37)), 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()