refactoring
Some checks failed
deploy / deploy (push) Failing after 1m56s

This commit is contained in:
2023-10-25 21:33:53 +03:00
parent 20e1fa989a
commit 1f5e5472c9
10 changed files with 7 additions and 126 deletions

42
services/notify.py Normal file
View File

@@ -0,0 +1,42 @@
import json
from services.rediscache import redis
async def notify_reaction(reaction, action: str = "create"):
channel_name = "reaction"
data = {
"payload": reaction,
"action": action
}
try:
await redis.publish(channel_name, json.dumps(data))
except Exception as e:
print(f"Failed to publish to channel {channel_name}: {e}")
async def notify_shout(shout, action: str = "create"):
channel_name = "shout"
data = {
"payload": shout,
"action": action
}
try:
await redis.publish(channel_name, json.dumps(data))
except Exception as e:
print(f"Failed to publish to channel {channel_name}: {e}")
async def notify_follower(follower: dict, author_id: int, action: str = "follow"):
fields = follower.keys()
for k in fields:
if k not in ["id", "name", "slug", "userpic"]:
del follower[k]
channel_name = f"follower:{author_id}"
data = {
"payload": follower,
"action": action
}
try:
await redis.publish(channel_name, json.dumps(data))
except Exception as e:
print(f"Failed to publish to channel {channel_name}: {e}")