https://prefect.io logo
d

dh

03/18/2021, 7:53 PM
hello, prefect team. I see there are the two methods available for flow registration. Are both equally recommended? 1. prefect cli [1] 2. functional API
flow.register
context: we want to create a dynamically defined flow (e.g.
Flow(result=S3Result(location=f'bucket/{<http://args.my|args.my>_result_key}', ...)
for flow reuse. To parse user-pass args, we instantiate the Flow behind
__main__
. Now we noticed we can’t use prefect cli to register because it can’t pass extra user args. Alternatively, we are considering
flow.register
and wonder if there would be any risks we should be aware of. [1]: https://github.com/PrefectHQ/prefect/blob/master/src/prefect/cli/register.py#L70
j

Jim Crist-Harif

03/18/2021, 7:54 PM
Nope, either should work fine. I encourage users to try to use the CLI when possible (for uniformity across flows), but both options are valid and supported.
d

dh

03/18/2021, 7:58 PM
awesome thank you @Jim Crist-Harif would you happen to have a reference example that does dynamically defined flows? (e.g. varying the result flow based on user-passed arg).
j

Jim Crist-Harif

03/18/2021, 7:59 PM
I'm not sure I understand what you're asking for.
d

dh

03/18/2021, 8:03 PM
sorry for the confusion. I look for a reference example in the prefect repo that “creates” (not executes) a Flow based on user-passed arguments and registers it. It’s okay if there’s none. :-) I just wanted to compare the example to the pattern I have in mind…
j

Jim Crist-Harif

03/18/2021, 9:07 PM
We don't have an example for that, but since flows are built programmatically in python, you should be able to write whatever logic you want.
Copy code
with Flow("example") as flow:
    if some_build_time_user_config_flag:
        x = some_task_a()
    else:
        x = some_task_b()
r

Ranu Goldan

03/29/2021, 3:12 AM
Hi @dh sorry for jumping in. Did you find way to dynamically create flow? (user-passed arguments) I am still confused how to make it work within the flow storage and flow register
@Kyle Moon-Wright
👋 1
d

dh

04/02/2021, 10:22 PM
Hello, sorry for the late reply. Thank you Jim for sharing the advice. And Ranu --- yes, basically I went ahead with what jim shared. so far, not a big problem identified yet…
r

Ranu Goldan

04/07/2021, 1:43 AM
Hi @dh thanks for your reply, I myself decided to find out how to do it with utilizing schedule default parameter.
💯 1
👍 1
3 Views