Ë
    §Œj¾%  ã                   óz  — 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 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+m,Z, d dl-m.Z.m/Z/m0Z0 d dl1m2Z2m3Z3m4Z4m5Z5 dZ6 G d„ de«      Z7de,fd„Z8e G d„ d«      «       Z9e G d„ d«      «       Z:y)é    )Ú	dataclassÚfield)ÚEnum)ÚListÚOptionalÚTypeÚUnionN)Ú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© ó    úf/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/redis/asyncio/multidb/config.pyr,   r,   0   s   „ Ø#€MØ-ÐØ#�Mr7   r,   Úreturnc                  ó   — t        «       S ©N)r!   r6   r7   r8   Údefault_event_dispatcherr<   6   s   € ÜÓÐr7   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_urlr9   c                 óX   — t        j                  | j                  ¬«      }t        |«      S )N)Úreset_timeout)Ú	pybreakerr$   rF   r%   )ÚselfÚcircuit_breakers     r8   Údefault_circuit_breakerz&DatabaseConfig.default_circuit_breaker\   s#   € Ü#×2Ñ2À×ARÑARÔSˆÜ& Ó7Ð7r7   )r0   r1   r2   Ú__doc__r?   ÚfloatÚ__annotations__r   ÚdictrB   rC   r   ÚstrrD   r
   rE   r$   r#   rF   rG   rM   r6   r7   r8   r>   r>   :   ss   … ñð0 €FˆEÓÙ°Ô5€M�4Ó5Ø"€Hˆh�s‰mÓ"Ø*.€Iˆx˜Ñ'Ó.Ø(,€GˆX�nÑ%Ó,Ø.€L�%Ó.Ø&*Ð�h˜s‘mÓ*ð8¨ô 8r7   r>   c                   óÊ  — e Zd ZU dZee   ed<   eZe	e
eef      ed<    e edd¬«      d¬«      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<   e-Z.eed<    e/e0¬«      Z1e2ed<   e3jh                  Z5e3ed<   de6fd„Z7dee   fd„Z8dee   fd„Z9d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_intervalr@   Úevent_dispatcherÚinitial_health_check_policyr9   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)ÚclientrE   r?   rG   r6   )r    rU   rB   Úupdater   r   rC   rV   rD   Ú	set_retryrE   rM   Úaddr   r?   rG   )rK   Ú	databasesÚdatabase_configrr   rE   s        r8   rv   zMultiDbConfig.databases¦   sT  € Ü “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  5ðH Ðr7   c                 ón   — t        t        | j                  | j                  | j                  ¬«      «      gS )N)r`   ra   Úfailure_detection_window)r   r)   r`   ra   rb   ©rK   s    r8   Údefault_failure_detectorsz'MultiDbConfig.default_failure_detectorsÏ   s7   € ä'Ü&Ø%)×%:Ñ%:Ø+/×+FÑ+FØ-1×-KÑ-Kôóð
ð 	
r7   c                 ó\   — t        | j                  | j                  | j                  ¬«      gS )N)re   rf   rg   )r   re   rf   rg   rz   s    r8   Údefault_health_checksz#MultiDbConfig.default_health_checksÚ   s/   € äØ$(×$<Ñ$<Ø#'×#:Ñ#:Ø%)×%>Ñ%>ôð
ð 	
r7   c                 ó   — t        «       S r;   )r   rz   s    r8   Údefault_failover_strategyz'MultiDbConfig.default_failover_strategyã   s   € Ü*Ó,Ð,r7   );r0   r1   r2   rN   r   r>   rP   r   rV   r   r	   r   r   r   r^   r_   r   r   r(   r`   Úintr&   ra   rO   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,   r3   rn   r   rv   r{   r}   r   r6   r7   r8   rT   rT   a   sj  … ñ)ðV ˜>Ñ*Ó*Ø5:€L�$�u˜U LÐ0Ñ1Ñ2Ó:Ù Ù,°!¸Ô<Àaô€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ó 
ð-Ð+@ô -r7   rT   );Údataclassesr   r   Úenumr   Útypingr   r   r   r	   rJ   Ú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<   r>   rT   r6   r7   r8   Ú<module>r�      s´   ðß (Ý ß .Ó .ã ç =Ñ =ß >÷ó ÷÷	÷ 	ó 	õ &ß AÝ -ß A÷ñ ÷
ó ð "%Ð ô$˜ô $ðÐ":ó ð ÷#8ð #8ó ð#8ðL ÷B-ð B-ó ñB-r7   