In prefect 3, i have a flow containing some tasks....
# ask-community
t
In prefect 3, i have a flow containing some tasks. When a task in the middle of a flow fail, will i get notification? And can i rerun that task to resume the flow from that task? Or can I skip the failed task and resume the flow after task? Thank you!
n
hi @Tri - to address both questions
When a task in the middle of a flow fail, will i get notification?
you can, you have to set up a notification. there are a couple ways to do that • create an automation • use an
on_failure
hook
And can i rerun that task to resume the flow from that task? Or can I skip the failed task and resume the flow after task?
yes! consider this example
Copy code
from prefect import flow, task
from prefect.cache_policies import INPUTS

count = 0

@task(cache_policy=INPUTS)
def double(x: int) -> int:
    global count
    if count == 1:
        return x * 2
    count += 1
    raise ValueError("Intentional failure")

@task(cache_policy=INPUTS)
def always_succeeds(x: int) -> int:
    return x + 1

@flow(retries=1, retry_delay_seconds=5)
def f():
    always_succeeds(3)
    return double(4)

f()
where we simulate a failure the first time, and then it succeeds on retry, and any upstream tasks that already completed would be cached