Review generated retry handlers

from Closures
Python 3.14 intermediate 8 min 3 issues to find

Review this generated code before it is used by the job runner.

Create one retry handler per job, track attempts independently, enforce max_attempts, and expose a read-only failure history.

Python
def build_retry_handlers(jobs, max_attempts):
    handlers = []
    failures = []

    for job in jobs:
        attempts = 0

        def retry():
            nonlocal attempts, failures
            if attempts > max_attempts:
                raise RuntimeError("retry limit reached")

            attempts += 1
            try:
                return job.run(attempts)
            except Exception as error:
                failures = failures + [(job.name, str(error))]
                raise

        handlers.append(retry)

    def failure_history():
        return tuple(failures)

    return handlers, failure_history

generated code is illustrative, not from any one model

Open in playground
Report an error