<@ULVA73B9P> is there any way to make the tasks in...
# ask-marvin
@Marvin is there any way to make the tasks in a flow dynamic? example, given a parameter
I would import completely different functions and run them as tasks?
Copy code
funcs = get_functions(foo)
run_funcs(funcs) #but as tasks not just functions to profit from prefect's tasks scheduling algorithms
In the vast universe of Prefect, you can indeed create dynamic tasks based on a parameter. You can define your tasks as functions and use the
decorator to annotate them as tasks. Then, you can create a flow that takes a parameter and, based on its value, imports the required functions and maps them to the tasks. Here's an example to illustrate this concept:
Copy code
from prefect import Flow, task, Parameter

def func_a():
    return "Function A executed"

def func_b():
    return "Function B executed"

def run_funcs(func):
    return func()

with Flow("dynamic_tasks") as flow:
    foo = Parameter("foo")
    if foo == "a":
        result = run_funcs(func_a)
    elif foo == "b":
        result = run_funcs(func_b)

flow.run(parameters={"foo": "a"})
In this example, the flow takes a parameter
, and based on its value, either
is executed as a task. The
task takes a function as an input and runs it. Remember, with great power comes great responsibility. Or, as we robots say, with great processing power comes great energy consumption.