Hello! There is a posibility create new flow run f...
# ask-community
b
Hello! There is a posibility create new flow run from code:
client.create_flow_run(
flow_id="d7bfb996-b8fe-4055-8d43-2c9f82a1e3c7",
flow_run_name="docs example hello-world"
)
But when run triggered by prefect the names are random. Or you can set manualy from UI flow_run_name. My tipical prefect script looks like :
@task
def task1():
pass
@task
def task1():
pass
with Flow() as flow:
task1()
task2()
...
client.register(flow, project_name='project')
Is there way set run_flow_name by default in code? For example:
name = f"name_{datetime.datetime.utc()}"
k
I was just typing this up for our FAQ. You can use a state handler with the RenameFlowRun task
Copy code
from prefect import Flow, task
from prefect.tasks.prefect import RenameFlowRun

def rename_handler(obj, new_state, old_state):
    if new_state.is_running():
        RenameFlowRun().run(flow_run_name="new_name")
    return

@task
def first_task():
    return 1

with Flow("test-flow", state_handlers=[rename_handler]) as flow:
    first_task()
1
upvote 1
b
@Kevin Kho thanks!