Last active
July 1, 2023 13:59
-
-
Save nsakki55/f44c09640e5bdec98f1d5fe83350d6ea to your computer and use it in GitHub Desktop.
rename custom flow run name for prefect 2.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from datetime import datetime | |
import prefect | |
from prefect import flow, task | |
@task(name="set flow run name task") | |
async def set_flow_run_name(name: str) -> None: | |
"""Set user specify flow run name.""" | |
task_run_context = prefect.context.get_run_context() | |
flow_run_id = task_run_context.task_run.flow_run_id | |
async with prefect.get_client() as client: | |
await client.update_flow_run(flow_run_id=flow_run_id, name=name) | |
@flow() | |
async def my_flow(): | |
now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
flow_name = f"my-flow-{now}" | |
await set_flow_run_name(name=flow_name) | |
if __name__ == "__main__": | |
asyncio.run(my_flow()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment