prioritize interactive requests over background checks in shared Lichess-token queue
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 15s
All checks were successful
CI/CD Pipeline / build-and-deploy (push) Successful in 15s
/today, /yesterday, /week were queuing behind the entire periodic-check backlog on the same rate-limited LICHESS_APP_TOKEN (observed ~2min wait on prod for a single command). Add a two-tier priority queue to SharedTokenGate: interactive on-demand requests jump ahead of background periodic checks, which still drain normally when nothing interactive is waiting. Verified locally end-to-end (isolated queue unit tests, live request with priority correctly reaching Lichess, and a real successful accuracy fetch rendered through StatsFormatter). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
0dbd0c400b
commit
d4eb61f994
6 changed files with 76 additions and 25 deletions
|
|
@ -698,7 +698,7 @@ class StatsService:
|
|||
total=create_game_stats(stats['total'])
|
||||
)
|
||||
|
||||
async def get_games_of_period(self, username: str, since_timestamp: int, until_timestamp: int, rated_only: bool = True, include_games: bool = False) -> GamesOfPeriodResponse:
|
||||
async def get_games_of_period(self, username: str, since_timestamp: int, until_timestamp: int, rated_only: bool = True, include_games: bool = False, priority: str = "background") -> GamesOfPeriodResponse:
|
||||
"""
|
||||
Получает статистику игр пользователя за определенный период.
|
||||
|
||||
|
|
@ -711,6 +711,8 @@ class StatsService:
|
|||
until_timestamp: Конец периода (Unix timestamp в секундах)
|
||||
rated_only: Только рейтинговые игры (по умолчанию True)
|
||||
include_games: Включить построчный список отдельных партий (только blitz/rapid/classical)
|
||||
priority: "interactive" для запросов из /today и т.п. (обгоняют фоновые
|
||||
периодические проверки в общей очереди shared_token_gate), иначе "background"
|
||||
|
||||
Returns:
|
||||
GamesOfPeriodResponse с статистикой игр
|
||||
|
|
@ -719,9 +721,9 @@ class StatsService:
|
|||
# Конвертируем timestamp в миллисекунды для API Lichess
|
||||
since_ms = since_timestamp * 1000
|
||||
until_ms = until_timestamp * 1000
|
||||
|
||||
|
||||
# Получаем игры (без фильтра rated в запросе к Lichess — см. lichess_client)
|
||||
games = await self.lichess_client.get_games_of_period(username, since_ms, until_ms, rated_only=False)
|
||||
games = await self.lichess_client.get_games_of_period(username, since_ms, until_ms, rated_only=False, priority=priority)
|
||||
|
||||
if games is None:
|
||||
return GamesOfPeriodResponse(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue