Split out main module
This commit is contained in:
31
src/knowledge_search_mcp/clients/base.py
Normal file
31
src/knowledge_search_mcp/clients/base.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# ruff: noqa: INP001
|
||||
"""Base client with shared aiohttp session management."""
|
||||
|
||||
import aiohttp
|
||||
|
||||
|
||||
class BaseGoogleCloudClient:
|
||||
"""Base class with shared aiohttp session management."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize session tracking."""
|
||||
self._aio_session: aiohttp.ClientSession | None = None
|
||||
|
||||
def _get_aio_session(self) -> aiohttp.ClientSession:
|
||||
"""Get or create aiohttp session with connection pooling."""
|
||||
if self._aio_session is None or self._aio_session.closed:
|
||||
connector = aiohttp.TCPConnector(
|
||||
limit=300,
|
||||
limit_per_host=50,
|
||||
)
|
||||
timeout = aiohttp.ClientTimeout(total=60)
|
||||
self._aio_session = aiohttp.ClientSession(
|
||||
timeout=timeout,
|
||||
connector=connector,
|
||||
)
|
||||
return self._aio_session
|
||||
|
||||
async def close(self) -> None:
|
||||
"""Close aiohttp session if open."""
|
||||
if self._aio_session and not self._aio_session.closed:
|
||||
await self._aio_session.close()
|
||||
Reference in New Issue
Block a user