fix(nox-api): address duplicate creation risks, pending upgrading issues, cache warm error handling, test speedups, and frontend display support for pending keys
This commit is contained in:
@@ -380,12 +380,14 @@ _RATE_LIMIT_BACKOFFS = (2, 5, 10, 20)
|
||||
_RATE_LIMIT_MAX_WAIT = 60
|
||||
|
||||
|
||||
def _retry_on_429(fn: Callable[[], Any], backoffs: tuple[int, ...] = _RATE_LIMIT_BACKOFFS) -> Any:
|
||||
def _retry_on_429(fn: Callable[[], Any], backoffs: tuple[float, ...] | None = None) -> Any:
|
||||
"""执行 fn(),若遇 429 则按退避序列重试,超限后抛 UpstreamError。
|
||||
|
||||
fn 应是 HTTP 调用;429 响应会被 httpx.HTTPStatusError 捕获(raise_for_status 之后)
|
||||
或者 fn 内部已经解析为 UpstreamError 且 message 含 429。
|
||||
"""
|
||||
if backoffs is None:
|
||||
backoffs = _RATE_LIMIT_BACKOFFS
|
||||
total_waited = 0
|
||||
for attempt, wait in enumerate(backoffs):
|
||||
try:
|
||||
@@ -783,7 +785,7 @@ class UpstreamClient:
|
||||
|
||||
缓存以 token name 为 key;同名取最新(id 最大)。
|
||||
"""
|
||||
all_tokens = self._list_all_new_api_tokens()
|
||||
all_tokens = _retry_on_429(lambda: self._list_all_new_api_tokens())
|
||||
cache: dict[str, dict[str, Any]] = {}
|
||||
for t in all_tokens:
|
||||
name = str(t.get("name") or t.get("key_name") or "")
|
||||
|
||||
Reference in New Issue
Block a user