Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions agentex/src/adapters/http/adapter_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def _get_streaming_client(cls) -> httpx.AsyncClient:

@classmethod
async def close_clients(cls) -> None:
# TODO: Call this method
"""Close and cleanup the shared clients. Call this during app shutdown for proper cleanup."""
"""Close and cleanup the shared clients. Called during app shutdown for proper cleanup."""
if cls._regular_client:
await cls._regular_client.aclose()
cls._regular_client = None
Expand Down
3 changes: 3 additions & 0 deletions agentex/src/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from fastapi.staticfiles import StaticFiles

from src.adapters.crud_store.exceptions import ItemDoesNotExist
from src.adapters.http.adapter_httpx import HttpxGateway
from src.api.authentication_middleware import AgentexAuthMiddleware
from src.api.health_interceptor import HealthCheckInterceptor
from src.api.logged_api_route import LoggedAPIRoute
Expand Down Expand Up @@ -68,6 +69,8 @@ async def lifespan(_: FastAPI):
await dependencies.startup_global_dependencies()
configure_statsd()
yield
# Clean up HTTP clients before other shutdown tasks
await HttpxGateway.close_clients()
await dependencies.async_shutdown()
dependencies.shutdown()

Expand Down
16 changes: 8 additions & 8 deletions agentex/src/domain/repositories/agent_api_key_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ async def get_internal_api_key_by_agent_id(
)

result = await session.execute(query)
agents = result.scalars().all()
return AgentAPIKeyEntity.model_validate(agents[0]) if agents else None
row = result.scalars().first()
return AgentAPIKeyEntity.model_validate(row) if row else None

async def get_by_agent_id_and_name(
self, agent_id: str, name: str, api_key_type: AgentAPIKeyType
Expand Down Expand Up @@ -109,8 +109,8 @@ async def get_by_agent_id_and_name(
)

result = await session.execute(query)
agents = result.scalars().all()
return AgentAPIKeyEntity.model_validate(agents[0]) if agents else None
row = result.scalars().first()
return AgentAPIKeyEntity.model_validate(row) if row else None

async def get_by_agent_name_and_key_name(
self, agent_name: str, key_name: str, api_key_type: AgentAPIKeyType
Expand Down Expand Up @@ -138,8 +138,8 @@ async def get_by_agent_name_and_key_name(
)

result = await session.execute(query)
agents = result.scalars().all()
return AgentAPIKeyEntity.model_validate(agents[0]) if agents else None
row = result.scalars().first()
return AgentAPIKeyEntity.model_validate(row) if row else None

async def get_external_by_agent_id_and_key(
self, agent_id: str, api_key: str
Expand Down Expand Up @@ -167,8 +167,8 @@ async def get_external_by_agent_id_and_key(
)

result = await session.execute(query)
agents = result.scalars().all()
return AgentAPIKeyEntity.model_validate(agents[0]) if agents else None
row = result.scalars().first()
return AgentAPIKeyEntity.model_validate(row) if row else None

async def delete_by_agent_name_and_key_name(
self, agent_name: str, key_name: str, api_key_type: AgentAPIKeyType
Expand Down
Loading