ForcePilot/backend/package/yuxi/channel/extensions/clickup/ratelimit.py
Kris a79fc8dd7b feat(clickup): 新增ClickUp聊天渠道插件完整实现
该提交实现了完整的ClickUp聊天渠道插件,包含以下核心功能:
1. 基础的@提及提取与格式化能力
2. 账号配对与会话管理
3. 消息流与流式回复支持
4. 重试限流与消息去重
5. 富文本格式转换与内容 sanitize
6. 安全策略与配置校验
7. Webhook接收与自动轮询回退
8. 消息收发、编辑、删除与回复
9. 频道与私信管理、反应功能
10. 完整的状态监控与健康检查
2026-05-21 10:43:19 +08:00

34 lines
1.1 KiB
Python

import asyncio
import logging
import httpx
logger = logging.getLogger(__name__)
MAX_RETRIES = 3
BASE_DELAY = 2.0
async def retry_with_backoff(coro_factory, max_retries: int = MAX_RETRIES):
for attempt in range(max_retries + 1):
try:
resp = await coro_factory()
if resp.status_code == 429:
retry_after = resp.headers.get("Retry-After", str(BASE_DELAY * (2**attempt)))
wait = float(retry_after)
logger.warning("clickup rate limited (429), retry after %.1fs, attempt %d", wait, attempt + 1)
await asyncio.sleep(wait)
continue
return resp
except httpx.HTTPStatusError:
if attempt < max_retries:
await asyncio.sleep(BASE_DELAY * (2**attempt))
else:
raise
except Exception:
if attempt < max_retries:
await asyncio.sleep(BASE_DELAY * (2**attempt))
else:
raise
raise RuntimeError("clickup rate limit exceeded after max retries")