
    j                         d dl Z d dlZd dlmZmZ ddlmZ ddlm	Z	 ddl
m
Z
  e j                  e      Zdeg ef   defd	Zd
ej                  dedefdZy)    N)AnyCallable   )client)ApiError)
rate_limitrest_callablereturnc                    	 	  |        }|S # t         $ r}|j                  dk(  r|j                  at        j                  |j                        }|@|j                         }t        j                  d|       t        j                  |       Y d}~t        j                  d       t        j                  d       Y d}~ d}~ww xY w)a  
    Execute a REST API call with automatic retry on rate limit (429) errors.

    This function handles HTTP 429 rate limit errors by waiting for the duration
    specified in the response headers and retrying the request. Regular retries
    for other errors are handled by the underlying rest client.

    Args:
        rest_callable: A callable that performs the REST API call.

    Returns:
        The result of the successful REST API call.

    Raises:
        ApiError: If the error is not a 429 rate limit error.
    i  Nz/Rate limited (HTTP 429), retrying in %s secondszHRate limited (HTTP 429) with no retry-after header, retrying in 1 second   )
r   status_codeheadersr   parse_rate_limitretry_afterLOGGERinfotimesleep)r	   result	exceptionrate_limiterr   s        v/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/api_objects/rest_helpers.py*ensure_rest_api_call_respecting_rate_limitr      s    & 	"_FM 	$$+$$0#-#>#>y?P?P#QL#/&2&>&>&@M' 

;/ ^ 

1'	s!    	CA7C*C CCrest_clientproject_namec                 R    | j                   j                  |      }|j                  S )a  
    Resolve a project name to its project ID.

    Args:
        rest_client: The REST API client instance.
        project_name: The name of the project.

    Returns:
        The project ID.

    Raises:
        ApiError: If the project is not found or if there's an API error.
    )name)projectsretrieve_projectid)r   r   projects      r   resolve_project_id_by_namer"   9   s'      ""333FG::    )loggingr   typingr   r   rest_apir   rest_api_clientrest_api.core.api_errorr   r   	getLogger__name__r   r   OpikApistrr"    r#   r   <module>r.      sk        0 . #			8	$*BG$**Z ((8;r#   