Реализовать ЛР 7 на оценку 3
This commit is contained in:
+6
-1
@@ -2,6 +2,8 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
import ssl
|
||||
|
||||
import aio_pika
|
||||
from aio_pika import DeliveryMode, ExchangeType
|
||||
@@ -15,10 +17,13 @@ logger = logging.getLogger('app.broker')
|
||||
|
||||
|
||||
async def connect(url: str) -> aio_pika.RobustConnection:
|
||||
context = None
|
||||
if url.startswith('amqps://'):
|
||||
context = ssl.create_default_context(cafile=os.getenv('TLS_CA_FILE'))
|
||||
delay = 0.5
|
||||
while True:
|
||||
try:
|
||||
return await aio_pika.connect_robust(url, timeout=5)
|
||||
return await aio_pika.connect_robust(url, timeout=5, ssl_context=context)
|
||||
except (OSError, aio_pika.exceptions.AMQPException):
|
||||
logger.warning('broker is not ready; reconnecting in %.1fs', delay)
|
||||
await asyncio.sleep(delay)
|
||||
|
||||
Reference in New Issue
Block a user