Kevin Weiler
09/30/2021, 2:14 PMRenameFlowRun
prefect task to rename my flow based on a value in the context. I noticed that if I try something like:
rename_flow = RenameFlowRun(flow_name=f"{prefect.context.today}")
It tries to evaluate the context at deploy time, instead of at runtime. Is there a reasonable way to do this?
@Rob Douglas ended up just pulling the guts out of the run()
method of RenameFlowRun
and putting it in a task. That works, but it seems a bit dodgy.
PS - the documentation for this is wrong, as the example shows importing FlowRenameTask
instead of RenameFlowRun
Kevin Kho
init
are executed immediately so even if you did something like datetime.datetime.now()
it would be persisted during build. The way around this is to create a function that returns prefect.context.today
so that it executes during runtime. And then I think you want,
with Flow(...) as flow:
RenameFlowRun()(flow_name=functioncall())
Kevin Kho
Kevin Weiler
09/30/2021, 2:24 PMwith Flow(...) as flow:
RenameFlowRun()(flow_name=prefect.context.today)
Wouldn’t work because the arguments are evaluated at deploy time correct?Kevin Kho
Kevin Kho
with Flow(...) as flow:
RenameFlowRun()(flow_name=task(lambda **args: prefect.context.today))
i think this will workKevin Weiler
09/30/2021, 2:26 PMKevin Weiler
09/30/2021, 2:27 PMKevin Kho
super.run()
.