0.0.2
All checks were successful
deploy / deploy (push) Successful in 1m21s

This commit is contained in:
2023-11-26 14:54:07 +03:00
parent 6e6de3818b
commit f4d4fd26d4
5 changed files with 25 additions and 23 deletions

View File

@@ -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)