2023-11-26 10:18:57 +00:00
|
|
|
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
|
|
|
"""создаеёт новое хранимое уведомление"""
|
2023-11-26 12:37:22 +00:00
|
|
|
with local_session() as session:
|
|
|
|
try:
|
2023-11-26 10:18:57 +00:00
|
|
|
n = Notification(**notification)
|
|
|
|
session.add(n)
|
2023-11-26 18:33:51 +00:00
|
|
|
session.commit()
|
2023-11-26 12:37:22 +00:00
|
|
|
except Exception as e:
|
|
|
|
session.rollback()
|
|
|
|
print(f"[listener.handle_reaction] error: {str(e)}")
|
2023-11-26 10:18:57 +00:00
|
|
|
|
|
|
|
|
2023-11-26 11:54:07 +00:00
|
|
|
async def reactions_worker():
|
|
|
|
async for message in redis.listen("reaction"):
|
2023-11-26 18:31:52 +00:00
|
|
|
if message:
|
2023-11-26 19:36:02 +00:00
|
|
|
await handle_reaction(message)
|