notifier/resolvers/listener.py
Untone 68fce283bc
All checks were successful
deploy / deploy (push) Successful in 1m18s
authorid-context
2023-11-28 19:04:45 +03:00

22 lines
685 B
Python

from orm.notification import Notification
from services.db import local_session
from services.rediscache import redis
async def handle_reaction(notification: dict[str, str | int]):
"""создаеёт новое хранимое уведомление"""
with local_session() as session:
try:
n = Notification(**notification)
session.add(n)
session.commit()
except Exception as e:
session.rollback()
print(f"[listener.handle_reaction] error: {str(e)}")
async def reactions_worker():
async for message in redis.listen("reaction"):
if message:
await handle_reaction(message)