diff --git a/src/fastapi_app/lib/db/brokers/broker.py b/src/fastapi_app/lib/db/brokers/broker.py index 3bb6904..396f4cf 100644 --- a/src/fastapi_app/lib/db/brokers/broker.py +++ b/src/fastapi_app/lib/db/brokers/broker.py @@ -1,11 +1,11 @@ -from contextlib import asynccontextmanager -from typing import AsyncGenerator, Type +import contextlib +import typing import lib.api.schemas as api_schemas class BrokerPublisher: - def __init__(self, broker_class: Type, settings: object): + def __init__(self, broker_class: typing.Type, settings: object): self.broker = broker_class(settings) async def connect(self): @@ -17,7 +17,7 @@ class BrokerPublisher: async def publish_message(self, message_body: api_schemas.BrokerMessage, routing_key: str): await self.broker.publish_message(message_body, routing_key) - @asynccontextmanager - async def get_connection(self) -> AsyncGenerator: + @contextlib.asynccontextmanager + async def get_connection(self) -> typing.AsyncGenerator: async with self.broker.get_connection() as conn: yield conn diff --git a/src/fastapi_app/lib/db/brokers/rabbitmq.py b/src/fastapi_app/lib/db/brokers/rabbitmq.py index c2fff73..3a2bbeb 100644 --- a/src/fastapi_app/lib/db/brokers/rabbitmq.py +++ b/src/fastapi_app/lib/db/brokers/rabbitmq.py @@ -1,6 +1,6 @@ import asyncio +import contextlib import json -from contextlib import asynccontextmanager import aio_pika @@ -36,7 +36,7 @@ class RabbitMQPublisher(db_brokers.base_broker.BasePublisher): message = aio_pika.Message(content_type="application/json", body=json.dumps(message_body).encode()) await self.channel.default_exchange.publish(message, routing_key=routing_key) - @asynccontextmanager + @contextlib.asynccontextmanager async def get_connection(self): if self.pool.empty() and self.pool.qsize() < self.pool_size: await self.connect()