def init_schedule(start, stop, dates: Tuple, **interval: int) -> Schedule: date_now, _, _, date_stop_serializable, date_start_serializable = dates clock = IntervalClock( start_date=date_now, interval=timedelta(**interval), parameter_defaults={ start.name: date_start_serializable, stop.name: date_stop_serializable } ) return Schedule(clocks=[clock])
for payment in payments: payment_temp = payments[payment] payment_temp["loan_id"] = payment 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(
from datetime import timedelta from prefect import Flow from prefect.schedules import Schedule from prefect.schedules.clocks import IntervalClock schedule = Schedule(clocks=[IntervalClock(timedelta(seconds=65))]) my_flow = Flow("Interval Test", schedule=schedule) my_flow.register(project_name="experimental")
}, }, { "type": "section", "text": { "type": "mrkdwn", "text": f"See all the new stargazers <https://github.com/{owner}/{repository}/stargazers|here>", }, }, ] } schedule = Schedule(clocks=[IntervalClock(timedelta(minutes=5))], filters=[is_weekday]) with Flow("Stargazers", schedule=schedule) as flow: """ Tasks: Repository [Parameter] Owner [Parameter] GetStars ShouldNotify NotificationMessage Notify [SlackTask] """ repository = Parameter("repository", default="prefect") owner = Parameter("owner", default="PrefectHQ") stars = GetStars(name="Get Stars",
from datetime import timedelta import pendulum from prefect import Flow, Parameter, task from prefect.schedules import Schedule from prefect.schedules.clocks import IntervalClock from prefect.schedules.filters import between_times, is_weekday @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:
return sample(range(100), length) @task def transform(data): return data * 10 @task def load(data): print(f"\nHere's your data: {data}") from prefect.schedules import Schedule from prefect.schedules.clocks import IntervalClock clock1 = IntervalClock( start_date=datetime.now() + timedelta(seconds=5), interval=timedelta(hours=1), parameter_defaults={"length": 6} ) clock2 = IntervalClock( start_date=datetime.now() + timedelta(seconds=15), interval=timedelta(hours=1), parameter_defaults={"length": 50} ) schedule = Schedule(clocks=[clock1, clock2]) with Flow("Evolving ETL", schedule=schedule) as flow: with case(length, 6): e = extract(length) t = transform.map(e) l = load(t)
return data * 10 @task(trigger=some_successful(at_least=1, at_most=6), state_handlers=[post_to_slack]) def load(data): # Load the data print(f"\nHere's your data: {data}") # Parameterized Scheduling from prefect.schedules import Schedule from prefect.schedules.clocks import IntervalClock, CronClock, DatesClock clock1, clock2 = IntervalClock( start_date=datetime.utcnow() + timedelta(seconds=10), interval=timedelta(hours=12), parameter_defaults={"length": 15}), IntervalClock( start_date=datetime.utcnow() + timedelta(seconds=10), interval=timedelta(hours=24), parameter_defaults={"length": 20}) schedule = Schedule(clocks=[clock1, clock2]) # Define Tasks in a Flow Context with Flow('Evolving ETL', result=S3Result(bucket="flow-result-storage"), state_handlers=[my_state_handler], schedule=schedule) as flow: with case(length, 5): e = extract(length) with case(length, 50):