Hi! How I can add the tasks in runtime? For exampl...
# ask-community
i
Hi! How I can add the tasks in runtime? For example: I am waiting for Parameter where should be count how many same tasks I want to create.
j
I sort of understand the first part of the question. when you call task inside flow and run the flow, the task gets added to the runtime.
import packages
@task
def some_func():
return
with flow("my-flow") as flow:
some_func_task=some_func()
flow.run()
z
Hi Igor, this might be a good use case for mapping.https://docs.prefect.io/core/concepts/mapping.html Something like the following pattern may work
Copy code
@task
def my_duplicated_task(idx):
  # do something

@task
def return_range(x):
  return [i for i in range(x)

with Flow('sample') as flow:
  x = Parameter(default=5)
  xrange = return_range(x)
  mapped_tasks = my_duplicated_task.map(xrange)