notifier/resolvers/listener.py
Untone 551bed52f1
Some checks failed
deploy / deploy (push) Has been cancelled
handling-message-filtering
2023-11-26 22:27:38 +03:00

31 lines
984 B
Python

import json
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"):
message = await message
if message:
msg_data = message.get("data")
if msg_data:
msg = json.loads(msg_data)
if msg.entity == "reaction":
await handle_reaction(msg)
else:
print(f"[resolvers.listener] unhandled msg: {msg}")