notifier/resolvers/listener.py
Untone 7ea2a911ef
All checks were successful
deploy / deploy (push) Successful in 1m12s
worker-fix
2023-11-26 22:36:02 +03:00

25 lines
713 B
Python

import json
import asyncio
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)