1
0
Fork 0

small fix

This commit is contained in:
Arthur K. 2026-04-25 13:18:04 +03:00
parent 5349befcf4
commit 89b85b321e
Signed by: wzray
GPG key ID: B97F30FDC4636357
8 changed files with 251 additions and 211 deletions

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import argparse
import asyncio
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
@ -28,7 +29,19 @@ async def run(data_dir: Path | None = None) -> None:
try:
for account in list(state.accounts):
try:
if account.token_refresh_at <= int(time.time()) + settings.token_refresh_buffer_seconds:
access_token, refresh_token, refresh_at = await client.refresh_access_token(
account.refresh_token
)
account.access_token = access_token
account.refresh_token = refresh_token
account.token_refresh_at = refresh_at
payload = await client.fetch_usage_payload(account.access_token)
email = payload.get("email")
if isinstance(email, str) and email:
previous_email = account.email
account.email = email
store.update_active_account(state, previous_email, email)
account.usage = parse_usage_payload(payload)
account.usage_checked_at = account.usage.checked_at
print(
@ -40,6 +53,14 @@ async def run(data_dir: Path | None = None) -> None:
)
except OpenAIAPIError as exc:
if exc.permanent:
usage = account.usage
print(
f"moving account to failed.json: email={account.email} reason=usage refresh auth failure: {exc} "
f"primary={usage.primary_window.used_percent if usage and usage.primary_window else 0}% "
f"primary reset in {format_reset_in(usage.primary_window.reset_at if usage and usage.primary_window else None)} "
f"secondary={usage.secondary_window.used_percent if usage and usage.secondary_window else 0}% "
f"secondary reset in {format_reset_in(usage.secondary_window.reset_at if usage and usage.secondary_window else None)}"
)
store.move_to_failed(state, account.email)
print(f"{account.email}: removed={exc}")
else: