Prem
04/17/2024, 3:46 PMMarvin
04/17/2024, 3:46 PMpython
from prefect import flow
from prefect.runtime import flow_run
@flow
def my_flow(name: str, limit: int = 100):
pass # Your flow logic here
def generate_flow_run_name():
flow_name = flow_run.flow_name # Retrieve the flow name
parameters = flow_run.parameters
name = parameters["name"]
limit = parameters["limit"]
return f"{flow_name}-with-{name}-and-{limit}"
my_flow(flow_run_name=generate_flow_run_name)
For deployment name, the documentation suggests that when a flow is run without a deployment, it will log "I belong to deployment None". If it is run as part of a deployment, it should log the name of the deployment instead. The runtime context will return an empty value when information is not available. See the Runtime Context documentation for more details and the full list of available attributes.
However, if you are looking to fetch these details for already completed flows, you would typically use the Prefect client within your Python code to query the Prefect API for this metadata. Unfortunately, the specific documentation or code examples for fetching these details post-run weren't directly found in this search. For more precise code examples, I would recommend looking into the Prefect Client documentation or contacting Prefect support.