From 379dbb4a1b72d1eba8f04672fdc903916004c663 Mon Sep 17 00:00:00 2001 From: grucshetskyaleksei Date: Mon, 2 Oct 2023 17:04:15 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fastapi_app/lib/db/brokers/broker.py | 10 +++++----- src/fastapi_app/lib/db/brokers/rabbitmq.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) 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()