Hey prefect devs, are default parameters (in this ...
# ask-community
g
Hey prefect devs, are default parameters (in this case dates) decided at the time a flow is registered or when the flow is executed following a daily schedule? I have a job that is registered to the prefect-server and takes in a date range wrt the date of execution. For example:
Copy code
with Flow("my_daily_flow", schedule) as flow:
    start_date = Parameter("start_date", default=datetime.utcnow().date() - timedelta(days=5))
    end_date = Parameter("start_date", default=datetime.utcnow().date())
    daily_job.set_dependencies(keyword_tasks={"start_date": start_date, "end_date": end_date})

flow.register("test")
This question might have been asked before, but I would like some confirmation. Thank you!
k
Hi @Goh Rui Zhi, if a flow is serialized (which is the default behavior)), these dates are saved during build time. If you want to bring it to the runtime, you can use a string like
Parameter("x", default = "today")
, then pass that to a task that returns today.
You can also used script based storage
g
I see. Thanks again @Kevin Kho!
👍 1
m
Hi, I have another question here on the subject. How can I get the value of a schedule to a parameter? E.g. if my schedule runs every hour, I want the time of the schedule. I understand I can get the current time, but what would happen if I restart the flow 3 days later? Which time would it use? Thanks!
Ok, it looks like this one works fine:
Copy code
run_dt = Parameter(name="run_dt", default=(schedule.next(1)[0] - timedelta(days=1)).strftime("%Y-%m-%d"))
thanks anyway 🙂
(I use module storage, and w/ it this works)