Adrien B
10/22/2021, 12:32 PMAnna Geller
Anna Geller
from prefect import Flow, Parameter, task
from prefect.executors import LocalDaskExecutor
plus_one = task(lambda x: x + 1)
with Flow("dummy-child-flow", executor=LocalDaskExecutor()) as flow:
numbers = Parameter("list_of_numbers", default=[1, 2, 3, 4, 5, 6, 7, 8, 9])
mapped_result = plus_one.map(numbers)
• a “parent” flow that handles triggering flow runs with 1000 tasks each:
from prefect import Flow, task, unmapped
from prefect.tasks.prefect import create_flow_run
from prefect.executors import LocalDaskExecutor
@task
def generate_thousand_numbers(start, stop, step):
nrs = range(start, stop, step)
return list(nrs)
with Flow("massively_mapped_flow", executor=LocalDaskExecutor()) as flow:
flow_run_1 = generate_thousand_numbers(1, 1000, 1)
flow_run_2 = generate_thousand_numbers(1000, 2000, 1)
flow_run_3 = generate_thousand_numbers(2000, 3000, 1)
flow_run_4 = generate_thousand_numbers(3000, 4000, 1)
flow_run_5 = generate_thousand_numbers(4000, 5000, 1)
# ... until 8
parameters = [
dict(list_of_numbers=flow_run_1),
dict(list_of_numbers=flow_run_2),
dict(list_of_numbers=flow_run_3),
dict(list_of_numbers=flow_run_4),
dict(list_of_numbers=flow_run_5),
# ... until 8
]
mapped_flows = create_flow_run.map(
parameters=parameters,
flow_name=unmapped("dummy-child-flow"),
project_name=unmapped("community"),
)
Adrien B
10/22/2021, 1:34 PMAnna Geller
Kevin Kho
Adrien B
10/22/2021, 1:51 PM