Files
notifier/resolvers/listener.py

22 lines
685 B
Python
Raw Normal View History

2023-11-26 13:18:57 +03:00
from orm.notification import Notification
from services.db import local_session
from services.rediscache import redis
2023-11-26 14:54:07 +03:00
async def handle_reaction(notification: dict[str, str | int]):
2023-11-26 13:18:57 +03:00
"""создаеёт новое хранимое уведомление"""
2023-11-26 15:37:22 +03:00
with local_session() as session:
try:
2023-11-26 13:18:57 +03:00
n = Notification(**notification)
session.add(n)
2023-11-26 21:33:51 +03:00
session.commit()
2023-11-26 15:37:22 +03:00
except Exception as e:
session.rollback()
print(f"[listener.handle_reaction] error: {str(e)}")
2023-11-26 13:18:57 +03:00
2023-11-26 14:54:07 +03:00
async def reactions_worker():
async for message in redis.listen("reaction"):
2023-11-26 21:31:52 +03:00
if message:
2023-11-26 22:36:02 +03:00
await handle_reaction(message)