<@ULVA73B9P> As a developer, I want to be able to...
# marvin-in-the-wild
e
@Marvin As a developer, I want to be able to rerun a flow from the last successful step so that I can reduce my testing and execution time. I want the that the flows can be manually rerun directly from Prefect UI and resume on the step before they failed and the task that completed successfully are not run again. How can I achieve this?
m
### Steps to Achieve Flow Reruns from Last Successful Step To accomplish the goal of manually rerunning a flow from the last successful step in Prefect, follow these steps: 1. Utilize Manual Flow Retries: Prefect has a feature for manually retrying flow runs which can be configured. This feature allows flows in terminal states to be rescheduled for retry. This can be useful for rerunning failed tasks while skipping successful ones. 2. Implementing the Retry Logic: When retrying, Prefect will orchestrate any tasks it discovers, ensuring only the necessary tasks are rerun. This drastically reduces overhead for flows with many tasks. 3. Configuration through Prefect UI: You can manually trigger reruns via the Prefect UI. Ensure your flow and tasks are defined in a way that supports resuming from failure by leveraging Prefect’s state handling. ### Example Here is a simple illustration of how to set up your retry logic:
Copy code
python
from prefect import flow, task
from prefect.engine.state import AwaitingRetry

@task
def task_that_succeeds():
    return "Success!"

@task
def task_that_fails():
    raise ValueError("Intentional Failure")

@flow
def my_flow():
    try:
        success_result = task_that_succeeds()
        fail_result = task_that_fails()
    except Exception as e:
        # Here you can define custom retry logic if necessary
        pass

if __name__ == '__main__':
    my_flow()
    # Trigger a retry or handle retries within the Prefect UI
### Documentation and Links 1. Manual flow retries Pull Request: Implements the ability to manually retry flow runs in terminal states. 2. Prefect Client Guide: Relevant for advanced client configurations. 3. Prefect Flows Concept: Detailed explanations on how flows are handled in Prefect. For the complete implementation and further customization, refer to the above resources. #### I hope this sets you up for less testing and efficient reruns. Sadly, nothing can cure the existential dread of endless tasks, but this helps. 🖖