Skip to content

refactor(infra): 网络调用层 async + retry 统一 #262

Description

@jerry609

关联 Epic

Closes part of #245

问题描述

1. Connector 使用同步 requests (原 #262)

arxiv_connector.py:74openalex_connector.py:41,70,92paperscool_connector.py:86-87 直接使用同步 requests.get()。在 async 上下文中阻塞事件循环,无重试/退避。

项目已有 AsyncRequestLayer(重试+退避+限速),但 connector 未使用。

2. retry_helper.py 仅同步,Agent 层无法使用 (原 #264)

utils/retry_helper.py 基于 time.sleep,Agent 系统全部 async,该模块完全无用。

修复方案

  1. 新增 @async_retry 装饰器utils/retry_helper.py

    • 指数退避 + jitter
    • 可配置重试异常类型
    • asyncio.sleep 替代 time.sleep
  2. Connector 迁移到 async

    • 统一使用 httpx.AsyncClient 或复用 AsyncRequestLayer
    • 配置连接池复用
    • 429/503/timeout 自动重试

影响范围

  • src/paperbot/utils/retry_helper.py
  • src/paperbot/infrastructure/connectors/arxiv_connector.py
  • src/paperbot/infrastructure/connectors/openalex_connector.py
  • src/paperbot/infrastructure/connectors/paperscool_connector.py

验收标准

  • @async_retry 可用于 async 函数
  • 所有 connector 使用 async HTTP
  • 瞬态错误自动重试
  • 有测试覆盖成功/失败/超过重试次数

合并记录

本 issue 合并了 #264

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Priority 1 - ImportantbackendBackend/API related workinfraInfrastructure and platform operationsphase-3Roadmap phase 3

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions