Skip to content

Retry 模块

重试装饰器,提供重试次数限制、重试延迟策略、异常类型过滤等功能。支持同步和异步函数。

快速开始

基本重试

python
from FQBase.Foundation import retry

@retry(stop_max_attempt_number=3, wait_random_min=100, wait_random_max=500)
def fetch_data():
    return api.get()

指数退避

python
from FQBase.Foundation import retry_with_exponential_backoff

@retry_with_exponential_backoff(max_attempts=5, base_wait=100, max_wait=5000)
def fetch_with_backoff():
    return api.get()

异常过滤

python
@retry(retry_on_exception=(ConnectionError, TimeoutError))
def fetch_data():
    return api.get()

核心功能

功能说明
retry固定/随机延迟重试装饰器
retry_with_exponential_backoff指数退避重试装饰器
async_retry_with_exponential_backoff异步指数退避重试
RetryContext重试上下文,手动控制重试
RetryError重试失败异常

重试策略

策略等待时间适用场景
固定随机random(min, max)快速恢复的临时故障
指数退避base * 2^(attempt-1)网络抖动、限流

文档索引

文档说明
README本文档,模块索引
框架模块架构与核心概念
架构设计与工作流程
API完整API参考
使用使用指南与示例
开发指南开发环境、调试、测试
最佳实践开发建议与注意事项
设计设计决策文档
FAQ常见问题解答