Spaces:
Sleeping
Sleeping
File size: 1,043 Bytes
1def50b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | # ============================================================================
# HTTP CLIENT MANAGER
# ============================================================================
import aiohttp
from typing import Optional
from app.config import Config
from app.utils.logger import logger
class HTTPClientManager:
"""Manages aiohttp session lifecycle"""
def __init__(self):
self.session: Optional[aiohttp.ClientSession] = None
async def start(self):
timeout = aiohttp.ClientTimeout(total=Config.REQUEST_TIMEOUT)
self.session = aiohttp.ClientSession(timeout=timeout)
logger.info("HTTP client session started")
async def close(self):
if self.session:
await self.session.close()
logger.info("HTTP client session closed")
def get_session(self) -> aiohttp.ClientSession:
if not self.session:
raise RuntimeError("HTTP client not initialized")
return self.session
# Global instance
http_client = HTTPClientManager()
|