Pascal Jahan Elahi (Pawsey)
01/20/2025, 7:48 AMMarvin
01/20/2025, 7:48 AM@task
decorator and provide the name
argument. Here's an example:
python
from prefect import task, flow
@task(name="My Custom Task Name")
def my_task():
print("Running my task")
@flow
def my_flow():
my_task()
my_flow()
This will create a task with the name "My Custom Task Name". You can find more details on writing tasks in the Prefect documentation.Pascal Jahan Elahi (Pawsey)
01/20/2025, 7:51 AMMarvin
01/20/2025, 7:51 AMtask_run_name
parameter. This parameter accepts a function that returns a string for the task run name, allowing you to dynamically define the name at runtime.
Here's an example:
python
from prefect import task, flow
from prefect.runtime import flow_run
@task(task_run_name=lambda: f"Task Run {flow_run.id}")
def my_task():
print("Running my task")
@flow
def my_flow():
my_task()
my_flow()
In this example, the task run name is dynamically set using a lambda function that formats the name with the flow run ID. You can customize this logic to include other runtime information as needed. More information can be found in the Prefect documentation.Pascal Jahan Elahi (Pawsey)
01/20/2025, 7:55 AMMarvin
01/20/2025, 7:55 AMtask_run_name
parameter in the @task
decorator. This parameter can be assigned a function that generates the name at runtime, allowing you to customize the task name based on runtime context or other dynamic information.
Here's a concise example:
python
from prefect import task, flow
from prefect.runtime import flow_run
@task(task_run_name=lambda: f"Dynamic Task Name {flow_run.id}")
def my_task():
print("Running my task")
@flow
def my_flow():
my_task()
my_flow()
In this example, the task run name is dynamically generated using a lambda function that incorporates the flow run ID. You can modify the lambda function to include any other runtime-specific data you need. For more details, refer to the Prefect documentation.