notifier/resolvers/listener.py

25 lines
721 B
Python
Raw Normal View History

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