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

Мелкие правки форматирования

This commit is contained in:
grucshetskyaleksei 2023-10-02 17:04:15 +03:00
parent f8df57844e
commit 379dbb4a1b
2 changed files with 7 additions and 7 deletions

View File

@ -1,11 +1,11 @@
from contextlib import asynccontextmanager import contextlib
from typing import AsyncGenerator, Type import typing
import lib.api.schemas as api_schemas import lib.api.schemas as api_schemas
class BrokerPublisher: class BrokerPublisher:
def __init__(self, broker_class: Type, settings: object): def __init__(self, broker_class: typing.Type, settings: object):
self.broker = broker_class(settings) self.broker = broker_class(settings)
async def connect(self): async def connect(self):
@ -17,7 +17,7 @@ class BrokerPublisher:
async def publish_message(self, message_body: api_schemas.BrokerMessage, routing_key: str): async def publish_message(self, message_body: api_schemas.BrokerMessage, routing_key: str):
await self.broker.publish_message(message_body, routing_key) await self.broker.publish_message(message_body, routing_key)
@asynccontextmanager @contextlib.asynccontextmanager
async def get_connection(self) -> AsyncGenerator: async def get_connection(self) -> typing.AsyncGenerator:
async with self.broker.get_connection() as conn: async with self.broker.get_connection() as conn:
yield conn yield conn

View File

@ -1,6 +1,6 @@
import asyncio import asyncio
import contextlib
import json import json
from contextlib import asynccontextmanager
import aio_pika 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()) 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) await self.channel.default_exchange.publish(message, routing_key=routing_key)
@asynccontextmanager @contextlib.asynccontextmanager
async def get_connection(self): async def get_connection(self):
if self.pool.empty() and self.pool.qsize() < self.pool_size: if self.pool.empty() and self.pool.qsize() < self.pool_size:
await self.connect() await self.connect()