dh

    dh

    1 year ago
    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
    Jim Crist-Harif

    Jim Crist-Harif

    1 year ago
    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.
    dh

    dh

    1 year ago
    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).
    Jim Crist-Harif

    Jim Crist-Harif

    1 year ago
    I'm not sure I understand what you're asking for.
    dh

    dh

    1 year ago
    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…
    Jim Crist-Harif

    Jim Crist-Harif

    1 year ago
    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.
    with Flow("example") as flow:
        if some_build_time_user_config_flag:
            x = some_task_a()
        else:
            x = some_task_b()
    r

    Ranu Goldan

    1 year ago
    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
    dh

    dh

    1 year ago
    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

    1 year ago
    Hi @dh thanks for your reply, I myself decided to find out how to do it with utilizing schedule default parameter.