Is there a way to get failed child tasks to re-run...
# prefect-community
h
Is there a way to get failed child tasks to re-run without re-running each child task individually? For example:
Copy code
import prefect
from prefect import Flow, task
from prefect.engine.results import PrefectResult

from random import random


@task
def make_data():
    return list(range(5))


@task
def randomly_raise(x):
    x = random()
    if x <= 0.5:
        raise Exception()


with Flow("test retries", result=PrefectResult()) as flow:
    data = make_data()
    randomly_raise.map(data)
When the above runs, it creates 5 mapped tasks, each of which randomly fail with 50% chance. When there are failed runs, if I click re-run on the failed tasks, I can get them to individually re-run & succeed. But, re-running on the entire flow never attempts the mapped tasks again. Here’s what’s logged
Copy code
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise': task is mapped, but run will proceed so children are generated."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise': Handling state change from Mapped to Mapped"
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[0]': Starting task run..."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise[0]': task is already finished."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[0]': finished task run for task with final state: 'Success'"
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[1]': Starting task run..."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise[1]': task is already finished."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[1]': finished task run for task with final state: 'Success'"
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[2]': Starting task run..."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise[2]': task is already finished."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[2]': finished task run for task with final state: 'Failed'"
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[3]': Starting task run..."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise[3]': task is already finished."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[3]': finished task run for task with final state: 'Failed'"
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[4]': Starting task run..."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,DEBUG,"Task 'randomly_raise[4]': task is already finished."
June 12th 2020,9:22:35am ,prefect.CloudTaskRunner,INFO,"Task 'randomly_raise[4]': finished task run for task with final state: 'Failed'"
Is there a way to re-run a whole group of mapped tasks?
j
Hey @Howard Cornwell I believe restarting from failed will only rerun tasks which are not successful in order to avoid duplicate work. Starting another run is one way of rerunning the whole group
h
Thanks, perhaps I should clarify the last question: is there a way to re-run all the failed child tasks of a mapped task?
j
Thanks for the clarification! Looking into it
@Howard Cornwell I think this is a bug because those tasks should be rerunning on restart. We’ll open an issue and get it fixed 🙂
🐛 1
h
Thanks, good to know I’m not going mad!
Hey, did the ticket for this get raised? I took a quick look on github but couldn’t see a related issue.
j
@Howard Cornwell let me check on that. The issue was UI related and not actually anything in the core code itself 🙂 will let you know when I find out
h
Thanks for the update