chore: handle noisy log messages
This commit is contained in:
parent
858d127246
commit
320460f7f4
4 changed files with 71 additions and 27 deletions
|
|
@ -43,6 +43,14 @@ class ChatGPTProvider(Provider):
|
|||
self.email_provider_factory = email_provider_factory or MailTmProvider
|
||||
self._token_write_lock = asyncio.Lock()
|
||||
|
||||
@property
|
||||
def prepare_threshold(self) -> int:
|
||||
return CHATGPT_PREPARE_THRESHOLD
|
||||
|
||||
@property
|
||||
def switch_threshold(self) -> int | None:
|
||||
return CHATGPT_SWITCH_THRESHOLD
|
||||
|
||||
async def _register_with_retries(self) -> bool:
|
||||
for attempt in range(1, CHATGPT_REGISTRATION_MAX_ATTEMPTS + 1):
|
||||
logger.info(
|
||||
|
|
@ -105,21 +113,23 @@ class ChatGPTProvider(Provider):
|
|||
|
||||
async def ensure_next_account(self) -> bool:
|
||||
next_tokens = load_next_tokens()
|
||||
if next_tokens and not next_tokens.is_expired:
|
||||
if next_tokens:
|
||||
return True
|
||||
|
||||
async with self._token_write_lock:
|
||||
next_tokens = load_next_tokens()
|
||||
if next_tokens and not next_tokens.is_expired:
|
||||
if next_tokens:
|
||||
return True
|
||||
return await self._create_next_account_under_lock()
|
||||
|
||||
def should_prepare_standby(self, usage_percent: int) -> bool:
|
||||
return usage_percent >= self.prepare_threshold
|
||||
|
||||
async def ensure_standby_account(
|
||||
self,
|
||||
usage_percent: int,
|
||||
prepare_threshold: int,
|
||||
) -> None:
|
||||
if usage_percent >= prepare_threshold:
|
||||
if self.should_prepare_standby(usage_percent):
|
||||
await self.ensure_next_account()
|
||||
|
||||
async def maybe_switch_active_account(self, usage_percent: int) -> bool:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue