https://prefect.io logo
Title
a

Andreas Nord

09/06/2022, 3:12 PM
Hi! I want to set the runtime name of a task depending on one of the arguments, without having to set name on every function call. Basically what is the Prefect 2 equivalent of the prefect 1 code below
from prefect import task, Flow


def foo(x):
    return _foo(x, task_args=dict(name=x))


@task(task_run_name="{x}")
def _foo(x):
    print(x)


with Flow("flow") as flow:
    foo('a') # should be named 'a' 
    foo('b') # should be named 'b'

flow()
1
Never mind, the with_options(name=x) in the _foo call seems to do the job
:upvote: 1
n

Nate

09/06/2022, 3:20 PM
yep spot on, that's what I would recommend for that