mirror of
https://github.com/ijaric/voice_assistant.git
synced 2025-05-24 14:33:26 +00:00
Мелкие правки форматирования
This commit is contained in:
parent
f8df57844e
commit
379dbb4a1b
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue
Block a user