标记 Token 使用失败
(self, token: str, error: Exception = None)
| 325 | logger.info(f"✅ Token 恢复可用: {token[:20]}...") |
| 326 | |
| 327 | def mark_token_failure(self, token: str, error: Exception = None): |
| 328 | """标记 Token 使用失败""" |
| 329 | with self._lock: |
| 330 | if token in self.token_statuses: |
| 331 | status = self.token_statuses[token] |
| 332 | status.total_requests += 1 |
| 333 | status.failure_count += 1 |
| 334 | status.last_failure_time = time.time() |
| 335 | |
| 336 | if status.failure_count >= self.failure_threshold: |
| 337 | status.is_available = False |
| 338 | logger.warning(f"🚫 Token 已禁用: {token[:20]}... (失败 {status.failure_count} 次)") |
| 339 | |
| 340 | async def record_token_success(self, token: str, dao=None): |
| 341 | """标记成功并实时同步数据库统计。""" |
no outgoing calls
no test coverage detected