Nikola Milushev
02/12/2021, 5:28 PMschedule = Schedule(clocks=[IntervalClock(timedelta(days=1))])
with Flow(name=name, schedule=schedule) as flow:
start_date = Parameter(name="start_date",
required=False,
default=(datetime.now() - timedelta(days=2)).strftime("%Y-%m-%d"))
end_date = Parameter(name="end_date",
required=False,
default=(datetime.now() - timedelta(days=1)).strftime("%Y-%m-%d"))
Jim Crist-Harif
02/12/2021, 5:31 PMdatetime.now()
runs then, and the parameter defaults are hardcoded. Then when you run it, the same default values (that were computed at registration time) are used.Jim Crist-Harif
02/12/2021, 5:33 PMJim Crist-Harif
02/12/2021, 5:33 PMNone
and handling the none case special in your code. Then at runtime you can compute the offset you desire.Jim Crist-Harif
02/12/2021, 5:36 PMfrom prefect import task, Parameter
@task
def normalize(date, days):
if date is None:
return (datetime.now() - timedelta(days=days)).strftime("%Y-%m-%d"))
return date
with Flow(name=name, schedule=schedule) as flow:
start_date = Parameter(name="start_date", required=False, default=None)
end_date = Parameter(name="end_date", required=False, default=None)
start_date = normalize(start_date, 2)
end_date = normalize(end_date, 1)
Nikola Milushev
02/12/2021, 5:39 PMJim Crist-Harif
02/12/2021, 5:39 PMNikola Milushev
02/12/2021, 5:40 PM