1
0
mirror of https://github.com/ijaric/voice_assistant.git synced 2025-05-24 14:33:26 +00:00

fix: httpx client & handler & router

This commit is contained in:
Artem Litvinov 2023-09-30 21:47:37 +01:00
parent 8f2065e31f
commit 9888f0e993
6 changed files with 18 additions and 12 deletions

View File

@ -1,5 +1,5 @@
from .health import * from .health import *
__all__ = [ __all__ = [
"health_router", "basic_router",
] ]

View File

@ -1,5 +1,5 @@
from .liveness_probe import router as health_router from .liveness_probe import basic_router
__all__ = [ __all__ = [
"health_router", "basic_router",
] ]

View File

@ -2,10 +2,10 @@ import fastapi
import lib.api.v1.schemas as api_shemas import lib.api.v1.schemas as api_shemas
router = fastapi.APIRouter() basic_router = fastapi.APIRouter()
@router.get( @basic_router.get(
"/", "/",
response_model=api_shemas.HealthResponseModel, response_model=api_shemas.HealthResponseModel,
summary="Статус работоспособности", summary="Статус работоспособности",

View File

@ -45,6 +45,7 @@ class Application:
logger.info("Initializing global clients") logger.info("Initializing global clients")
postgres_client = clients.AsyncPostgresClient(settings=settings) postgres_client = clients.AsyncPostgresClient(settings=settings)
http_client = clients.get_async_http_session()
disposable_resources.append( disposable_resources.append(
DisposableResource( DisposableResource(
@ -72,10 +73,10 @@ class Application:
# Handlers # Handlers
logger.info("Initializing handlers") logger.info("Initializing handlers")
# liveness_probe_handler = health_handlers.LivenessProbeHandler() liveness_probe_handler = api_v1_handlers.basic_router
logger.info("Creating application") logger.info("Creating application")
# aio_app = aiohttp_web.Application()
fastapi_app = fastapi.FastAPI( fastapi_app = fastapi.FastAPI(
title=settings.app.title, title=settings.app.title,
@ -86,7 +87,7 @@ class Application:
) )
# Routes # Routes
fastapi_app.include_router(api_v1_handlers.health_router, prefix="/api/v1/health", tags=["health"]) fastapi_app.include_router(liveness_probe_handler, prefix="/api/v1/health", tags=["health"])
application = Application( application = Application(
settings=settings, settings=settings,

View File

@ -1,3 +1,4 @@
from .httpx import get_async_http_session
from .postgres import AsyncPostgresClient from .postgres import AsyncPostgresClient
__all__ = ["AsyncPostgresClient"] __all__ = ["AsyncPostgresClient", "get_async_http_session"]

View File

@ -1,4 +1,3 @@
# Purpose: Provide an example of an async http client for the application
import contextlib import contextlib
import typing import typing
@ -6,7 +5,12 @@ import httpx
@contextlib.asynccontextmanager @contextlib.asynccontextmanager
async def get_http_client() -> typing.AsyncGenerator[httpx.AsyncClient, None]: async def get_async_http_session(
client = httpx.AsyncClient() # Insert your own settings here settings: dict[str, typing.Any] | None = None
) -> typing.AsyncGenerator[httpx.AsyncClient, None]:
"""Async http client."""
if settings is None:
settings = {}
client = httpx.AsyncClient(**settings) # Insert your own settings here
async with client as ac: async with client as ac:
yield ac yield ac