https://prefect.io logo
d

damien michelle

03/01/2022, 3:05 PM
Hi, I'm new to prefect and I am facing an issue. I have a flow A which takes a country_code as a paremeter. I would like to know how to map the flow A to a list of country_code ? Currently, I was thinking triggering the flow A by mapping the flow A to each country_code specified in a flow B (as shown in the images) Thanks by advance
k

Kevin Kho

03/01/2022, 3:08 PM
Hi @damien michelle, it is a bit less straightfroward to do it with a subflow if you can avoid it because you need to use the
get_task_run_result
task in order to pull it out back into the main Flow. It will be easier if you could capture this in a task and use the task int he main flow.
d

damien michelle

03/01/2022, 3:19 PM
Hi @Kevin Kho, Do you have an example to illustrate what you suggest ?
k

Kevin Kho

03/01/2022, 3:26 PM
There is an example in this blog. Look for the
get_task_run_result
d

damien michelle

03/01/2022, 3:46 PM
I don't understand how this helps in my case where i want "to map" a flow
k

Kevin Kho

03/01/2022, 3:56 PM
Sorry I’m confused here. You can just do
create_flow_run.map()
right?
something like this?
Copy code
@task
def get_params_list(codes):
    res = []
    for code in codes:
        res.append({"country_code":code}
    return res

with Flow(...) as flow:
    codes = Parameter("codes", [123, 456])
    params_list = get_params_list(codes)
    create_flow_run.map(flow_name=unmapped("name"), project_name=unmapped("name"), parameters=params_list)
d

damien michelle

03/01/2022, 4:18 PM
It's exactly what I was searching for ! Thx you @Kevin Kho 👍