https://prefect.io logo
Title
e

E Li

02/23/2022, 4:21 PM
Hi, if I have 2 sub-flows in a main flow like below, can the flow_b get the output of flow_a as its input?
with Flow(...) as flow:
    data = extract_some_data()
    flow_a = create_flow_run(…, parameters={'param-key':data})
    flow_b = create_flow_run(…,parameters={'param-key':output_from_flow_a})
k

Kevin Kho

02/23/2022, 4:22 PM
You need to use the
get_task_run_result
task to pull a result from
flow_a
and then pass it in to
flow_b
e

E Li

02/23/2022, 4:31 PM
i notice that the function asks for flow_run_id, it's generated by prefect right? is there a way to retrieve that in code?
k

Kevin Kho

02/23/2022, 4:38 PM
the
flow_a
will be the run id because
create_flow_run
returns it
e

E Li

02/23/2022, 4:44 PM
got it, so say this is my code. if task_a and task_b are both mapped with 10 items, will prefect execute in a depth first way? namely if item 1 finished first then it will go right to flow_b
with Flow(...) as flow:
  data = extract_some_data()
  flow_a = create_flow_run(…, parameters={'param-key':data})
  flow_a_result = get_task_run_result(flow_a, task_a_slug)
  flow_b = create_flow_run(…,parameters={'param-key': flow_a_result})

with Flow(...) as flow_a:
  data = Parameter('param-key')
  a = task_a.map(data)

with Flow(...) as flow_b:
  data = Parameter('param-key')
  b = task_b.map(data)
k

Kevin Kho

02/23/2022, 4:45 PM
I believe so
e

E Li

02/23/2022, 4:51 PM
cool, the reason of having sub-flow is really to maintain the ability of running a portion of the main flow independently. more than happy to know if there is better way of achieving that
k

Kevin Kho

02/23/2022, 4:51 PM
Of course! That makes sense!
e

E Li

02/23/2022, 4:52 PM
great, thanks