如何 cache/target Flow 中具有相同名称的任务与 prefect?

How to cache/target tasks with the same name in a Flow with prefect?

我正在尝试寻找 target 模式或缓存配置来区分流程中具有相同名称的任务。

如上图所示,只有一个任务被缓存,另一个被覆盖。我尝试使用 task-slug 但无济于事。

@task(
    name="process_resource-{task_slug}",
    log_stdout=True,
    target=task_target
    )

提前致谢

您似乎在尝试格式化任务名称而不是目标。 (任务名称不是可模板化的字符串)。

以下片段可能是您想要的:

@task(name="process_resource", log_stdout=True, target="{task_name}-{task_slug}")

经过进一步研究,documentation 似乎直接解决了动态更改任务配置的问题 - 不会破坏目标位置模板。

@task
def number_task():
    return 42

with Flow("example-v3") as f:
    result = number_task(task_args={"name": "new-name"})

print(f.tasks) # {<Task: new-name>}