简体   繁体   中英

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

I am trying to find a target pattern or cache config to differentiate between tasks with the same name in a flow.

在此处输入图像描述

As highlighted from the diagram above only one of the tasks gets cached and the other get overwritten. I tried using task-slug but to no avail.

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

Thanks in advance

It looks like you are attempting to format the task name instead of the target. (task names are not template-able strings).

The following snippet is probably what you want:

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

After further research it looks like the documentation directly addresses changing task configuration on the fly - Without breaking target location templates.

@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>}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM