Jen Evenson
02/16/2023, 9:50 PMprefect.context.flow_name
in Prefect 2?Marvin
02/16/2023, 9:51 PMprefect.context.flow_name
in Prefect 2 becomes set when the flow is run and can be customized using the flow_run_name
keyword argument, as per the RELEASE-NOTES.md at main · PrefectHQ/prefect · GitHub. You can provide a custom static name as the task_run_name
and a custom but a fixed name as the flow_run_name
in the flow. For example, you can use the following code:
from datetime import datetime
from prefect import flow, task
@task(task_run_name="custom-static-name")
def my_task(name):
print(f"hi {name}")
@flow(flow_run_name="custom-but-fixed-name")
def my_flow(name: str, date: datetime):
return my_task(name)
my_flow()
I hope this answer is satisfactory. Have a great day!Jen Evenson
02/16/2023, 9:53 PMMarvin
02/16/2023, 9:53 PMprefect deployment inspect
command, as per the instructions on the [Flow deployments page](https://docs.prefect.io/tutorials/deployments/) of the Prefect 2 documentation. Additionally, if you are using Prefect Cloud, you can use the [Prefect Cloud Quickstart guide](https://docs.prefect.io/ui/cloud-quickstart/) to quickly get up and running with Prefect. I hope this is sufficient information to answer your question.Nate
02/16/2023, 11:52 PMIn [6]: from prefect import flow
In [7]: from prefect.context import get_run_context
In [8]: @flow(log_prints=True)
...: def prints_flow_name():
...: print(f"Hello from {get_run_context().flow.name}!")
...:
In [9]: prints_flow_name()
17:49:34.257 | INFO | prefect.engine - Created flow run 'marigold-goldfish' for flow 'prints-flow-name'
17:49:35.258 | INFO | Flow run 'marigold-goldfish' - Hello from 'prints-flow-name'!
17:49:35.411 | INFO | Flow run 'marigold-goldfish' - Finished in state Completed()
and in case you meant flow_run
name, you get that the same way with {get_run_context().flow_run.name}
Marvin
02/16/2023, 11:52 PMflow_name
in Prefect 2, you can use the get_run_context().flow.name
command to get the flow name and get_run_context().flow_run.name
to retrieve the flow_run name. You can see an example of how to use this code in the code block you provided. I hope this is the information you are looking for.