-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
25 lines (19 loc) · 804 Bytes
/
tasks.py
File metadata and controls
25 lines (19 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import redis
import json
# Defina o canal corretamente
CHANNEL = "canal_eventos"
def publish_event(cliente_id: int, action_params: str):
"""
Publica uma mensagem no canal 'canal_eventos'.
"""
try:
# Criar conexão com Redis
redis_client = redis.Redis.from_url("redis://redis:6379", decode_responses=True)
# Criar mensagem
message = {"cliente_id": cliente_id, "action_params": action_params}
# Publicar no canal
result = redis_client.publish(CHANNEL, json.dumps(message))
# Debug para confirmar que foi publicado
print(f"[DEBUG] Mensagem publicada no canal {CHANNEL}: {message}, Retorno do Redis: {result}")
except Exception as e:
print(f"[ERROR] Falha ao publicar no canal {CHANNEL}: {e}")