Ë
    3ýjf&  ã                   óŽ  — d dl mZmZ d dlmZ d dlmZmZmZm	Z	 d dl
Z
d dlmZmZmZ d dlmZmZmZ d dlmZmZ d dlmZmZmZmZ d d	lmZmZ d d
lmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z& d dl'm(Z( d dl)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4 d dl5m6Z6m7Z7m8Z8m9Z9 dZ: G d„ de«      Z;de0fd„Z<e G d„ d«      «       Z=e G d„ d«      «       Z>y)é    )Ú	dataclassÚfield)ÚEnum)ÚListÚOptionalÚTypeÚUnionN)ÚDEFAULT_RETRY_BASEÚDEFAULT_RETRY_CAPÚDEFAULT_RETRY_COUNT)ÚConnectionPoolÚRedisÚRedisCluster)ÚDatabaseÚ	Databases)ÚDEFAULT_FAILOVER_ATTEMPTSÚDEFAULT_FAILOVER_DELAYÚAsyncFailoverStrategyÚWeightBasedFailoverStrategy)ÚAsyncFailureDetectorÚFailureDetectorAsyncWrapper)ÚDEFAULT_HEALTH_CHECK_DELAYÚDEFAULT_HEALTH_CHECK_INTERVALÚDEFAULT_HEALTH_CHECK_POLICYÚDEFAULT_HEALTH_CHECK_PROBESÚDEFAULT_HEALTH_CHECK_TIMEOUTÚHealthCheckÚHealthCheckPoliciesÚPingHealthCheck)ÚRetry)ÚExponentialWithJitterBackoffÚ	NoBackoff)ÚWeightedList)ÚEventDispatcherÚEventDispatcherInterface)ÚDEFAULT_GRACE_PERIODÚCircuitBreakerÚPBCircuitBreakerAdapter)ÚDEFAULT_FAILURE_RATE_THRESHOLDÚ!DEFAULT_FAILURES_DETECTION_WINDOWÚDEFAULT_MIN_NUM_FAILURESÚCommandFailureDetectoréx   c                   ó   — e Zd ZdZdZdZy)ÚInitialHealthCheckÚall_availableÚmajority_availableÚone_availableN)Ú__name__Ú
__module__Ú__qualname__ÚALL_AVAILABLEÚMAJORITY_AVAILABLEÚONE_AVAILABLE© ó    úV/root/telegram-saas/.venv/lib/python3.12/site-packages/redis/asyncio/multidb/config.pyr/   r/   1   s   „ Ø#€MØ-ÐØ#�Mr:   r/   Úreturnc                  ó   — t        «       S ©N)r$   r9   r:   r;   Údefault_event_dispatcherr?   7   s   € ÜÓÐr:   c                   ó¦   — e Zd ZU dZdZeed<    ee¬«      Z	eed<   dZ
ee   ed<   dZee   ed<   dZee   ed	<   eZeed
<   dZee   ed<   defd„Zy)ÚDatabaseConfigaÝ  
    Dataclass representing the configuration for a database connection.

    This class is used to store configuration settings for a database connection,
    including client options, connection sourcing details, circuit breaker settings,
    and cluster-specific properties. It provides a structure for defining these
    attributes and allows for the creation of customized configurations for various
    database setups.

    Attributes:
        weight (float): Weight of the database to define the active one.
        client_kwargs (dict): Additional parameters for the database client connection.
        from_url (Optional[str]): Redis URL way of connecting to the database.
        from_pool (Optional[ConnectionPool]): A pre-configured connection pool to use.
        circuit (Optional[CircuitBreaker]): Custom circuit breaker implementation.
        grace_period (float): Grace period after which we need to check if the circuit could be closed again.
        health_check_url (Optional[str]): URL for health checks. Cluster FQDN is typically used
            on public Redis Enterprise endpoints.

    Methods:
        default_circuit_breaker:
            Generates and returns a default CircuitBreaker instance adapted for use.
    g      ð?Úweight©Údefault_factoryÚclient_kwargsNÚfrom_urlÚ	from_poolÚcircuitÚgrace_periodÚhealth_check_urlr<   c                 óX   — t        j                  | j                  ¬«      }t        |«      S )N)Úreset_timeout)Ú	pybreakerr'   rI   r(   )ÚselfÚcircuit_breakers     r;   Údefault_circuit_breakerz&DatabaseConfig.default_circuit_breaker]   s#   € Ü#×2Ñ2À×ARÑARÔSˆÜ& Ó7Ð7r:   )r3   r4   r5   Ú__doc__rB   ÚfloatÚ__annotations__r   ÚdictrE   rF   r   ÚstrrG   r   rH   r'   r&   rI   rJ   rP   r9   r:   r;   rA   rA   ;   ss   … ñð0 €FˆEÓÙ°Ô5€M�4Ó5Ø"€Hˆh�s‰mÓ"Ø*.€Iˆx˜Ñ'Ó.Ø(,€GˆX�nÑ%Ó,Ø.€L�%Ó.Ø&*Ð�h˜s‘mÓ*ð8¨ô 8r:   rA   c                   óÊ  — e Zd ZU dZee   ed<   eZe	e
eef      ed<    e eee¬«      e¬«      Zeed<   dZeee      ed<   eZeed	<   eZeed
<   eZeed<   dZeee      ed<   eZ eed<   e!Z"eed<   e#Z$eed<   e%Z&eed<   e'Z(e)ed<   dZ*ee+   ed<   e,Z-eed<   e.Z/eed<   e0Z1eed<    e2e3¬«      Z4e5ed<   e6jn                  Z8e6ed<   de9fd„Z:dee   fd„Z;dee   fd„Z<de+fd„Z=y)ÚMultiDbConfigaì	  
    Configuration class for managing multiple database connections in a resilient and fail-safe manner.

    Attributes:
        databases_config: A list of database configurations.
        client_class: The client class used to manage database connections.
        command_retry: Retry strategy for executing database commands.
        failure_detectors: Optional list of additional failure detectors for monitoring database failures.
        min_num_failures: Minimal count of failures required for failover
        failure_rate_threshold: Percentage of failures required for failover
        failures_detection_window: Time interval for tracking database failures.
        health_checks: Optional list of additional health checks performed on databases.
        health_check_interval: Time interval for executing health checks.
        health_check_probes: Number of attempts to evaluate the health of a database.
        health_check_delay: Delay between health check attempts.
        health_check_timeout: Timeout for the full health check operation (including all probes).
        health_check_policy: Policy for determining database health based on health checks.
        failover_strategy: Optional strategy for handling database failover scenarios.
        failover_attempts: Number of retries allowed for failover operations.
        failover_delay: Delay between failover attempts.
        auto_fallback_interval: Time interval to trigger automatic fallback.
        event_dispatcher: Interface for dispatching events related to database operations.
        initial_health_check_policy: Defines the policy used to determine whether the databases setup is
                                     healthy during the initial health check.

    Methods:
        databases:
            Retrieves a collection of database clients managed by weighted configurations.
            Initializes database clients based on the provided configuration and removes
            redundant retry objects for lower-level clients to rely on global retry logic.

        default_failure_detectors:
            Returns the default list of failure detectors used to monitor database failures.

        default_health_checks:
            Returns the default list of health checks used to monitor database health
            with specific retry and backoff strategies.

        default_failover_strategy:
            Provides the default failover strategy used for handling failover scenarios
            with defined retry and backoff configurations.
    Údatabases_configÚclient_class)ÚbaseÚcap)ÚbackoffÚretriesÚcommand_retryNÚfailure_detectorsÚmin_num_failuresÚfailure_rate_thresholdÚfailures_detection_windowÚhealth_checksÚhealth_check_intervalÚhealth_check_probesÚhealth_check_delayÚhealth_check_timeoutÚhealth_check_policyÚfailover_strategyÚfailover_attemptsÚfailover_delayÚauto_fallback_intervalrC   Úevent_dispatcherÚinitial_health_check_policyr<   c           	      óà  — t        «       }| j                  D �]S  }|j                  j                  dt	        dt        «       ¬«      i«       |j                  r2 | j                  j                  |j                  fi |j                  ¤Ž}n}|j                  rU|j                  j                  t	        dt        «       ¬«      «       | j                  j                  |j                  ¬«      }n | j                  di |j                  ¤Ž}|j                  €|j                  «       n|j                  }|j                  t        |||j                  |j                  ¬«      |j                  «       �ŒV |S )NÚretryr   )r]   r\   )Úconnection_pool)ÚclientrH   rB   rJ   r9   )r#   rX   rE   Úupdater    r"   rF   rY   rG   Ú	set_retryrH   rP   Úaddr   rB   rJ   )rN   Ú	databasesÚdatabase_configrr   rH   s        r;   rv   zMultiDbConfig.databasesª   sY  € Ü “Nˆ	à#×4Ñ4ó "	ˆOð ×)Ñ)×0Ñ0Øœ%¨´9³;Ô?Ð@ôð ×'Ò'Ø3˜×*Ñ*×3Ñ3Ø#×,Ñ,ñØ0?×0MÑ0Mñ‘ð !×*Ò*Ø×)Ñ)×3Ñ3Ü !¬Y«[Ô9ôð ×*Ñ*×4Ñ4Ø$3×$=Ñ$=ð 5ó ‘ð +˜×*Ñ*ÑK¨_×-JÑ-JÑK�ð #×*Ñ*Ð2ð  ×7Ñ7Ô9à$×,Ñ,ð ð
 �M‰MÜØ!Ø#Ø*×1Ñ1Ø%4×%EÑ%Eô	ð  ×&Ñ&öð5"	ðH Ðr:   c                 ón   — t        t        | j                  | j                  | j                  ¬«      «      gS )N)r`   ra   Úfailure_detection_window)r   r,   r`   ra   rb   ©rN   s    r;   Údefault_failure_detectorsz'MultiDbConfig.default_failure_detectorsÓ   s7   € ä'Ü&Ø%)×%:Ñ%:Ø+/×+FÑ+FØ-1×-KÑ-Kôóð
ð 	
r:   c                 ó\   — t        | j                  | j                  | j                  ¬«      gS )N)re   rf   rg   )r   re   rf   rg   rz   s    r;   Údefault_health_checksz#MultiDbConfig.default_health_checksÞ   s/   € äØ$(×$<Ñ$<Ø#'×#:Ñ#:Ø%)×%>Ñ%>ôð
ð 	
r:   c                 ó   — t        «       S r>   )r   rz   s    r;   Údefault_failover_strategyz'MultiDbConfig.default_failover_strategyç   s   € Ü*Ó,Ð,r:   )>r3   r4   r5   rQ   r   rA   rS   r   rY   r   r	   r   r    r!   r
   r   r   r^   r_   r   r   r+   r`   Úintr)   ra   rR   r*   rb   rc   r   r   rd   r   re   r   rf   r   rg   r   rh   r   ri   r   r   rj   r   rk   ÚDEFAULT_AUTO_FALLBACK_INTERVALrl   r   r?   rm   r%   r/   r6   rn   r   rv   r{   r}   r   r9   r:   r;   rW   rW   b   sq  … ñ)ðV ˜>Ñ*Ó*Ø5:€L�$�u˜U LÐ0Ñ1Ñ2Ó:Ù Ù,Ø#Ð):ô
ð $ô	€M�5ó ð ?CÐ�x Ð%9Ñ :Ñ;ÓBØ4Ð�cÓ4Ø$BÐ˜EÓBØ'HÐ˜uÓHØ15€M�8˜D Ñ-Ñ.Ó5Ø#@Ð˜5Ó@Ø:Ð˜Ó:Ø :Ð˜Ó:Ø">Ð˜%Ó>Ø/JÐÐ,ÓJØ9=Ð�xÐ 5Ñ6Ó=Ø6Ð�sÓ6Ø2€N�EÓ2Ø$BÐ˜EÓBÙ16Ø0ô2ÐÐ.ó ð 7I×6VÑ6VÐÐ!3ÓVð'˜9ó 'ðR	
¨4Ð0DÑ+Eó 	
ð
 t¨KÑ'8ó 
ð-Ð+@ô -r:   rW   )?Údataclassesr   r   Úenumr   Útypingr   r   r   r	   rM   Úredis._defaultsr
   r   r   Úredis.asyncior   r   r   Úredis.asyncio.multidb.databaser   r   Úredis.asyncio.multidb.failoverr   r   r   r   Ú&redis.asyncio.multidb.failure_detectorr   r   Ú!redis.asyncio.multidb.healthcheckr   r   r   r   r   r   r   r   Úredis.asyncio.retryr    Úredis.backoffr!   r"   Úredis.data_structurer#   Úredis.eventr$   r%   Úredis.multidb.circuitr&   r'   r(   Úredis.multidb.failure_detectorr)   r*   r+   r,   r�   r/   r?   rA   rW   r9   r:   r;   ú<module>r‘      sº   ðß (Ý ß .Ó .ã ç VÑ Vß =Ñ =ß >÷ó ÷÷	÷ 	ó 	õ &ß AÝ -ß A÷ñ ÷
ó ð "%Ð ô$˜ô $ðÐ":ó ð ÷#8ð #8ó ð#8ðL ÷E-ð E-ó ñE-r:   