1
0
Fork 0

Compare commits

..

6 commits

4 changed files with 8 additions and 14 deletions

View file

@ -71,9 +71,8 @@ class Provider(ABC):
"""Usage percent when provider may switch active account/token.""" """Usage percent when provider may switch active account/token."""
return None return None
def should_prepare_standby(self, usage_percent: int) -> bool: def should_prepare_standby(self) -> bool:
"""Whether standby preparation should be triggered for current usage.""" """Whether standby preparation should be triggered for current usage."""
_ = usage_percent
return False return False
async def ensure_standby_account( async def ensure_standby_account(

View file

@ -122,8 +122,8 @@ class ChatGPTProvider(Provider):
return True return True
return await self._create_next_account_under_lock() return await self._create_next_account_under_lock()
def should_prepare_standby(self, usage_percent: int) -> bool: def should_prepare_standby(self) -> bool:
return usage_percent >= self.prepare_threshold and not bool(load_next_tokens()) return bool(load_next_tokens())
async def ensure_standby_account( async def ensure_standby_account(
self, self,

View file

@ -49,7 +49,7 @@ def should_trigger_standby_prepare(provider_name: str, usage_percent: int) -> bo
provider = PROVIDERS.get(provider_name) provider = PROVIDERS.get(provider_name)
if not provider: if not provider:
return False return False
return provider.should_prepare_standby(usage_percent) return provider.should_prepare_standby()
async def ensure_provider_token_ready(provider_name: str): async def ensure_provider_token_ready(provider_name: str):
@ -88,7 +88,7 @@ async def ensure_standby_task(provider_name: str, usage_percent: int, reason: st
if not provider: if not provider:
return return
if not provider.should_prepare_standby(usage_percent): if not provider.should_prepare_standby():
return return
try: try:
@ -212,7 +212,6 @@ async def on_cleanup(app: web.Application):
def create_app() -> web.Application: def create_app() -> web.Application:
app = web.Application()
app.on_startup.append(on_startup) app.on_startup.append(on_startup)
app.on_cleanup.append(on_cleanup) app.on_cleanup.append(on_cleanup)
app.router.add_get("/health", health_handler) app.router.add_get("/health", health_handler)
@ -221,7 +220,7 @@ def create_app() -> web.Application:
return app return app
def main(): if __name__ == "__main__":
logger.info("Starting token service on port %s", PORT) logger.info("Starting token service on port %s", PORT)
chatgpt_provider = PROVIDERS.get("chatgpt") chatgpt_provider = PROVIDERS.get("chatgpt")
if chatgpt_provider: if chatgpt_provider:
@ -240,7 +239,3 @@ def main():
port=PORT, port=PORT,
access_log_class=AccessLogger, access_log_class=AccessLogger,
) )
if __name__ == "__main__":
main()

View file

@ -34,8 +34,8 @@ class FakeProvider(Provider):
def prepare_threshold(self) -> int: def prepare_threshold(self) -> int:
return self._prepare_threshold return self._prepare_threshold
def should_prepare_standby(self, usage_percent: int) -> bool: def should_prepare_standby(self) -> bool:
return usage_percent >= self.prepare_threshold return False
@property @property
def name(self) -> str: def name(self) -> str: