Tomas Moreno
06/04/2024, 3:18 PMflow_run_name
parameter? is there any way to set the flow run name in the middle of a flow?Marvin
06/04/2024, 3:18 PMflow_run_name
parameter at the start before the flow executes.
Here are a few key points gathered from the documentation and issues:
1. Static Assignment at Declaration:
You can name the flow run using the flow_run_name
parameter at the time of flow declaration. This can be either a string or a function that generates a string:
python
from prefect import flow
import datetime
def generate_flow_run_name():
date = datetime.datetime.now(datetime.timezone.utc)
return f"{date:%A}-is-a-nice-day"
@flow(flow_run_name=generate_flow_run_name)
def my_flow(name: str):
pass
my_flow(name="marvin")
Source
2. Utilizing prefect.runtime
:
If accessing information dynamically within the flow is needed, using the prefect.runtime
module is advised:
python
from prefect import flow
from prefect.runtime import flow_run
def generate_flow_run_name():
flow_name = flow_run.flow_name
parameters = flow_run.parameters
name = parameters["name"]
limit = parameters["limit"]
return f"{flow_name}-with-{name}-and-{limit}"
@flow(flow_run_name=generate_flow_run_name)
def my_flow(name: str, limit: int = 100):
pass
my_flow(name="marvin")
Source
There is currently no way to dynamically set or change the flow_run_name
once the flow run has started or in the middle of the flow execution. You may want to follow the Prefect GitHub repository for any new updates or feature requests that may address this in the future.
These resources should help in ensuring you are best handling the flow run names in Prefect!Tomas Moreno
06/04/2024, 3:23 PMdate
parameter to something like {{ datetime.date.today() }}
Marvin
06/04/2024, 3:23 PM{{ datetime.date.today() }}
) into a prefect.yaml
configuration file is not inherently supported. Prefect's YAML configuration expects static values.
However, here's a potential workaround to dynamically set parameters, such as a date
, from within the Prefect flow itself:
1. Define the parameter in prefect.yaml
:
yaml
parameters:
date: null
2. Set the default dynamically in your flow code:
python
from prefect import flow
from datetime import date
@flow
def my_flow(date: str = str(date.today())):
print(f"The flow is running with date: {date}")
if __name__ == "__main__":
my_flow()
This would ensure that the date
parameter is set to today's date if not provided explicitly when the flow is triggered.
### Key Points:
- Static Definition: prefect.yaml
configurations are static.
- Dynamic Assignment: Use Python code within the flow to set defaults dynamically.
For more detailed documentation, refer to the Prefect concepts and deployment guides:
- Prefect Deployment with `prefect.yaml`
- Prefect Schedules and Parameters
In case you want to perform more dynamic operations, consider utilizing Prefect's Python client to programmatically create or modify deployments.
Feel free to check these sources for deeper insights:
- Prefect GitHub - Dynamic Parameters Issues
Hopefully, you're satisfied with this solution—for all the good it will do you.Tomas Moreno
06/04/2024, 3:24 PMMarvin
06/04/2024, 3:24 PMBring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.
Powered by