This commit is contained in:
@@ -5,7 +5,7 @@ from services.db import local_session
|
||||
from services.rediscache import redis
|
||||
|
||||
|
||||
def handle_reaction(notification: dict[str, str | int]):
|
||||
async def handle_reaction(notification: dict[str, str | int]):
|
||||
"""создаеёт новое хранимое уведомление"""
|
||||
try:
|
||||
with local_session() as session:
|
||||
@@ -17,20 +17,8 @@ def handle_reaction(notification: dict[str, str | int]):
|
||||
print(f"[listener.handle_reaction] error: {str(e)}")
|
||||
|
||||
|
||||
def stop(pubsub):
|
||||
pubsub.unsubscribe()
|
||||
pubsub.close()
|
||||
|
||||
|
||||
def start():
|
||||
pubsub = redis.pubsub()
|
||||
pubsub.subscribe("reaction")
|
||||
try:
|
||||
# Бесконечный цикл прослушивания
|
||||
while True:
|
||||
msg = pubsub.get_message()
|
||||
handle_reaction(json.loads(msg["data"]))
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
stop(pubsub)
|
||||
async def reactions_worker():
|
||||
async for message in redis.listen("reaction"):
|
||||
msg = json.loads(message["data"])
|
||||
if msg:
|
||||
await handle_reaction(msg)
|
||||
|
Reference in New Issue
Block a user