
    ug

                         d dl mZmZ d dlZd dlmZmZmZmZ d dl	m
Z
  G d dej                  ej                        Zy)    )OptionalSetN)retrystop_after_attemptwait_exponential_jitterretry_if_result)Spanc                       e Zd ZU dZeed<   eej                     ed<   d e	ej                  j                  ej                  j                  g      fdedeej                     ddfdZd Zd	 Zd
 Zd Zd Zy) RetryOnRpcErrorClientInterceptorz
    A gRPC client interceptor that retries RPCs on specific status codes. By default, it retries on UNAVAILABLE and UNKNOWN status codes.

    This interceptor should be placed after the OpenTelemetry interceptor in the interceptor list.
    max_attemptsretryable_status_codes   returnNc                      || _         || _        y N)r   r   )selfr   r   s      I/var/www/openai/venv/lib/python3.12/site-packages/chromadb/proto/utils.py__init__z)RetryOnRpcErrorClientInterceptor.__init__   s     )&<#    c                      d fd}t        t        dd      t         j                        t	         fd      |      fd       } |||      S )Nc                 :    ddl m} ||j                  d      y y )Nr   )tracerzWaiting to retry RPC) chromadb.telemetry.opentelemetryr   
start_span)_r   
sleep_spans     r   before_sleepzFRetryOnRpcErrorClientInterceptor._intercept_call.<locals>.before_sleep    s$    ? !#../EF
 "r   g?)jitterc                 <    | j                         j                  v S r   )coder   )xr   s    r   <lambda>zBRetryOnRpcErrorClientInterceptor._intercept_call.<locals>.<lambda>*   s    AFFH8S8S,Sr   )waitstopr   r   c                  <    j                          d  | i |S r   )end)argskwargscontinuationr   s     r   wrappedzARetryOnRpcErrorClientInterceptor._intercept_call.<locals>.wrapped'   s*     % !
000r   )r   r   r   r   r   )r   r)   client_call_detailsrequest_or_iteratorr   r*   r   s   ``    @r   _intercept_callz0RetryOnRpcErrorClientInterceptor._intercept_call   s\    %)
	G 
(S9#D$5$56!"ST%	

	1

	1 *,?@@r   c                 (    | j                  |||      S r   r-   r   r)   r+   requests       r   intercept_unary_unaryz6RetryOnRpcErrorClientInterceptor.intercept_unary_unary6       ##L2EwOOr   c                 (    | j                  |||      S r   r/   r0   s       r   intercept_unary_streamz7RetryOnRpcErrorClientInterceptor.intercept_unary_stream9   r3   r   c                 (    | j                  |||      S r   r/   r   r)   r+   request_iterators       r   intercept_stream_unaryz7RetryOnRpcErrorClientInterceptor.intercept_stream_unary<        ##L2EGWXXr   c                 (    | j                  |||      S r   r/   r7   s       r   intercept_stream_streamz8RetryOnRpcErrorClientInterceptor.intercept_stream_streamA   r:   r   )__name__
__module____qualname____doc__int__annotations__r   grpc
StatusCodesetUNAVAILABLEUNKNOWNr   r-   r2   r5   r9   r<    r   r   r   r      s     00 7:__(($//*A*AB8
== !$DOO 4= 
=A2PPY
Yr   r   )typingr   r   rC   tenacityr   r   r   r   opentelemetry.tracer	   UnaryUnaryClientInterceptorUnaryStreamClientInterceptorr   rH   r   r   <module>rN      s1       X X $=Y$$d&G&G=Yr   