what if i want to name the flow ?
# ask-community
k
what if i want to name the flow ?
d
The
Flow
initializer has a
name
keyword arg you can pass to it 🙂 i.e.,
with Flow(name="prod-etl")
. Edit: ah nevermind! My bad.
k
I think he wants to name the Flow run instead of the Flow The flow run name can not be set beforehand, but it can be changed when the run is created using the RenameFlowRun task. This can be used inside the Flow, or through a Flow state handler. The task can be used inside the state handler by calling the .run() method.
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()
k
what will happen if i use the same flow run name again and again?
is that a problem?
k
I don’t think it is, but I think you lose a bit of visibility on the dashboard. More commonly when you want to control the renaming, you want to insert some kind of date or parameter value to make it more identifiable.
k
let me elaborate on my problem maybe itll help you assist me. right now i have a flow i run with different tables and envs as parameters. this flow does a simple transformation. i have no visibility to which of the flow instances does which table transform right now
dont see the parameters in the scheduel and the name is just some docker container name
so i figured that as a start ill just name the flow after the table and env
is this good practice? or am i doing it all wrong?
k
I understand. Modifying the previous code example, you want something like this:
Copy code
from prefect import Flow, task, Parameter
from prefect.tasks.prefect import RenameFlowRun
import prefect

def rename_handler(obj, new_state, old_state):
    if new_state.is_running():
        new_name = f"myflow-{prefect.context.parameters["x"]}"
        RenameFlowRun().run(flow_run_name=new_name)
    return

@task
def first_task():
    return 1

with Flow("test-flow", state_handlers=[rename_handler]) as flow:
    param = Parameter("x", "test")
    first_task()
No it’s not wrong. It’s a common request. Prefect 2.0 will let users supply their own flow run names.
k
thank you kevin
k
of course!