请在任务运行器使用这段生成的代码前进行审查。
为每个任务创建一个重试处理器,独立记录尝试次数,执行 max_attempts 限制,并提供只读失败记录。
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
生成代码仅作示例,不代表任何特定模型