Ë
    1¨Šjì  ã                   ó¢  — d dl Z d dlm Z d dlZd dlZd dlmZ d dlmZ d dl	m
ZmZ d dlmZ  ej                   e«      ZeeegZ ej*                  ej,                  ej.                  ej0                  ej2                  ej4                  rej6                  nej8                  d dddd	dd
 e edd¬«      d¬«      e¬«      Zd„ Z e«       Z de!de"fd„Z#y)é    N)ÚRetry)ÚExponentialBackoff)ÚConnectionErrorÚTimeoutError)ÚsettingsTé2   é<   é
   é   g      ð?gš™™™™™©?)ÚcapÚbaseé   )Úretries)ÚhostÚportÚusernameÚpasswordÚconnection_classÚdbÚdecode_responsesÚmax_connectionsÚsocket_timeoutÚsocket_connect_timeoutÚsocket_keepaliveÚhealth_check_intervalÚretryÚretry_on_errorc                  ó6   — t        j                  t        ¬«      S )z3Returns an async Redis client from the managed pool)Úconnection_pool)ÚredisÚRedisÚ
redis_pool© ó    ú7/var/www/html/strategist-ai/app/services/infra/redis.pyÚget_redis_clientr&   )   s   € ä�;‰;¤zÔ2Ð2r$   ÚchannelÚdatac              ƒ   ó¸   ‡ ‡K  — ˆ ˆfd„}t        j                   |«       «      }t        j                  |«       |j	                  t        j
                  «       y­w)aU  Publish a JSON event to a Redis channel.

    Fires in the background and returns immediately: a stale connection's
    retry policy can take up to socket_timeout(60s) * retries(3) = 180s to
    recover (see redis_pool's comment above), and no caller -- a chat reply,
    a ticket update -- should ever wait on a websocket notification.
    c               “   ó€  •K  — 	 t        «       } | 4 ƒd {  –—†  t        j                  ‰«      }| j                  ‰|«      ƒ d {  –—†  t        j                  d‰› �«       d d d «      ƒd {  –—†  y 7 Œ\7 Œ/7 Œ	# 1 ƒd {  –—†7  sw Y   y xY w# t        $ r%}t        j                  d‰› d|› �«       Y d }~y d }~ww xY w­w)NzPublished event to z"Error publishing to Redis channel z: )r&   ÚjsonÚdumpsÚpublishÚloggerÚinfoÚ	ExceptionÚerror)ÚclientÚmessageÚer'   r(   s      €€r%   Ú_do_publishz"publish_event.<locals>._do_publish:   s±   øè ø€ ð	Nä%Ó'ˆFØ÷ =ñ =ÜŸ*™* TÓ*�Ø—n‘n W¨gÓ6×6Ð6Ü—‘Ð1°'°Ð;Ô<÷=÷ =ñ =øà6øð=ø÷ =÷ =ñ =ûô ò 	NÜ�L‰LÐ=¸g¸YÀbÈÈÐL×MÑMûð	Nüs‘   ƒB>…B •A2–B ™+A8ÁA4ÁA8Á!B Á,A6Á-B Á1B>Á2B Á4A8Á6B Á8B
Á>BÁ?B
ÂB Â	B>Â
B Â	B;ÂB6Â1B>Â6B;Â;B>N)ÚasyncioÚcreate_taskÚ_publish_tasksÚaddÚadd_done_callbackÚdiscard)r'   r(   r5   Útasks   ``  r%   Úpublish_eventr=   2   sC   ùè ø€ õ	Nô ×Ñ™{›}Ó-€DÜ×Ñ�tÔØ×Ñœ>×1Ñ1Õ2ùs   „AA)$r6   Úredis.asyncior    r+   ÚloggingÚredis.asyncio.retryr   Úredis.backoffr   Úredis.exceptionsr   ÚRedisConnectionErrorr   ÚRedisTimeoutErrorÚapp.core.configr   Ú	getLoggerÚ__name__r.   ÚConnectionResetErrorÚ	_RETRY_ONÚConnectionPoolÚ
REDIS_HOSTÚ
REDIS_PORTÚ
REDIS_USERÚREDIS_PASSWORDÚ	REDIS_SSLÚSSLConnectionÚ
Connectionr"   r&   Úsetr8   ÚstrÚdictr=   r#   r$   r%   ú<module>rU      sÙ   ðÛ Ý Û Û Ý %Ý ,ß gÝ $à	ˆ×	Ñ	˜8Ó	$€ð "Ð#4Ð6JÐK€	à!ˆU×!Ñ!Ø	×	Ñ	Ø	×	Ñ	Ø× Ñ Ø×$Ñ$Ø,4×,>Ò,>�U×(Ò(ÀE×DTÑDTØØØØØØØÙ
Ñ" s°Ô6ÀÔ
BØô€
ò"3ñ “€ð3 ð 3¨Dô 3r$   