bypass-empty

This commit is contained in:
Untone 2024-01-23 11:44:37 +03:00
parent 95e070825f
commit 140e46e9f2

View File

@ -3,6 +3,10 @@ from resolvers.model import NotificationReaction, NotificationAuthor, Notificati
from services.db import local_session
from services.rediscache import redis
import asyncio
import logging
logger = logging.getLogger(f"[listener.listen_task] ")
logger.setLevel(logging.DEBUG)
class ServiceMessage:
@ -24,16 +28,17 @@ async def handle_notification(n: ServiceMessage, channel: str):
session.commit()
except Exception as e:
session.rollback()
print(f"[listener.handle_reaction] error: {str(e)}")
logger.error(f"[listener.handle_reaction] error: {str(e)}")
async def listen_task(pattern):
async for message_data, channel in redis.listen(pattern):
try:
notification_message = ServiceMessage(**message_data)
await handle_notification(notification_message, str(channel))
if message_data:
notification_message = ServiceMessage(**message_data)
await handle_notification(notification_message, str(channel))
except Exception as e:
print(f"[listener.listen_task] Error processing notification: {str(e)}")
logger.error(f"Error processing notification: {str(e)}")
async def notifications_worker():