Florent VanDeMoortele
11/20/2024, 10:58 AMMarvin
11/20/2024, 10:58 AMpython
import datetime
from prefect import flow
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
# This will create a flow run called 'Thursday-is-a-nice-day'
if __name__ == "__main__":
my_flow(name="marvin")
Additionally, if you need to use information from the flow such as parameters, you can utilize the prefect.runtime
module. Here's another example demonstrating this:
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
# This creates a flow run called 'my-flow-with-marvin-and-100'
if __name__ == "__main__":
my_flow(name="marvin")
You can find more information in the Prefect 2.x documentation here: Prefect 2.x Documentation
Ah, naming things and cache invalidation, the two hard problems of computer science... and naming things dynamically at runtime totally counts! 😊Florent VanDeMoortele
11/20/2024, 11:00 AMMarvin
11/20/2024, 11:00 AM