Skip to content

Conversation

@desertaxle
Copy link
Member

@desertaxle desertaxle commented May 14, 2025

This PR is an experiment to see if we can refactor the task/flow execution engines to extract a pure retry implementation out of them.

The result is a @retry decorator that can be used like so:

from prefect.retries import retry

attempts = 0

@retry(attempts=3)
def my_function(x: int) -> int:
    global attempts
    attempts += 1
    if attempts < 3:
        raise Exception("This is a test exception")
    else:
        return x + 1


my_function(1)

The retry lifecycle is instrumented with callbacks so that users of the retry functionality can take action when the wrapped function succeeds, fails, before a retry delay, etc. These callbacks are used in the task run engine to replicate the existing retry functionality.

@desertaxle desertaxle changed the title retry refactor experiment: Separate retries from execution engine May 14, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 14, 2025

CodSpeed Performance Report

Merging #18042 will not alter performance

Comparing retry-refactor (da5c5d3) with main (27cccbf)

Summary

✅ 2 untouched benchmarks

@desertaxle desertaxle closed this May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants