Hi Team, Maybe someone knows how to make a custom ...
# ask-community
i
Hi Team, Maybe someone knows how to make a custom run name for the flow run. For example, I don't want to see a random run name (red-octopus) , I want see <flow_name>_<datetime>.
j
Hi @Igor Bondartsov - If you're using the UI you can add a name in the run page If you're using the CLI you can use the --run-name flag
Or if you want it in your code, maybe try the renameFlowRun task: https://docs.prefect.io/api/latest/tasks/prefect.html#renameflowrun
i
@Jenny Thank you!
s
Hey Jenny, is it possible to change the default name though? All the above methods require you to do this on a flow run by flow run basis. Is there something you can do when registering a flow to set a naming template?
i
@Jenny Samuel Hinton has a good question above
j
Yes - that's where you'd use the renameFlowRun task!
Here's what I used:
Copy code
from prefect import Flow, task
import prefect
from prefect.tasks.prefect.flow_run_rename import RenameFlowRun

@task()
def getId():
    return prefect.context.get('flow_run_id')

rename_flow = RenameFlowRun()

with Flow(name='simple-flow') as flow:
    runId = getId
    rename_flow(flow_run_id=runId, flow_run_name="A new flow run name")

flow.register(project_name='ProjectName')
🙏 1
s
Hi @Jenny, Im not sure that would work. The idea I believe (for both Igor and I) is, for example, I have schedule a flow that runs at 6pm every day. Im looking for something like this:
Copy code
flow.register(project_name=self.project, name="Send email at {date}")
I believe right now using
renameFlowRun
this is renaming a specific flow run, and I would need to continually run this every day when a new flow is scheduled (unless Ive misread things) I have a manual solution right now for when backfilling (@Igor Bondartsov maybe this is useful?), but not for future scheduled tasks:
Copy code
self.client.create_flow_run(
    flow_id,
    parameters=p,
    run_name=f"{flow_name} @ {date_name}",
    scheduled_start_time=start,
)
👍 1
j
You can add that task to your flow to rename all your future runs. (These are from a schedule but I used 'start now' so I had a few to show you.)
❤️ 2
s
Ah that indeed could be use, thanks Jenny! Didnt realise you could use that within a flow itself, I was imaging having to do some graphql queries to get scheduled flows, this is so much nicer!
👍 1
j
@Marvin open "Write an idiom to show using the renameFlowRun task"
m
c
I think we could explore ways of allowing for run templates but it gets tricky because we have to be careful with what variables we template with — @Samuel Hinton / @Igor Bondartsov what are some of the run name templates you’d ideally like to use?
s
Ideally the variables in the context (like the scheduled time) and run parameters. The example that springs to mind for me is specifying logging formats in python - theres a default but extra variables are available for use if you want
i
Totally agree. For example, I am using Schedule(clocks=[clock1, clock2]) with parameter_defaults. I want to see where is clock1 runs and where is clock2.
c
Ok cool cool thanks, this is super helpful