Hi, is there a way to also add an incremental inte...
# ask-community
t
Hi, is there a way to also add an incremental integer to
task_run_name
if the task is running multiple times? https://docs.prefect.io/2.14.3/concepts/tasks/
Copy code
@task(name="My Example Task", 
      description="An example task for a tutorial.",
      task_run_name="hello-{name}-on-{date:%A}")
def my_task(name, date):
    pass
n
hi @Tony Yun - yes! you can pass a callable to
task_run_name
that retrieves the
dynamic_key
from the task run context, which could look like
Copy code
from prefect import flow, task
from prefect.context import get_run_context

def incremental_name():
   return f"Run {get_run_context().task_run.dynamic_key}" # modify as needed

@task(task_run_name=incremental_name)
def foo():
   pass

@flow
def someflow():
   foo()
   foo()
   foo()

someflow()
which gives
t
got it. Thanks @Nate!