o
    -i	                     @   s~   d Z ddl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
mZ eeZ		dd	e	d
e
dejdededefddZdS )z*Utilities for checking endpoint readiness.    N)tqdm)init_logger   )RequestFuncRequestFuncInputRequestFuncOutputX     request_func
test_inputsessiontimeout_secondsretry_intervalreturnc              	      s,  t  | }tdd}td| d t|dddq}	 |t   }|| }	t|	|j ||j }
||
 |  |d	krD|	  n@z#| ||d
I dH }|j
r_|	  |W W  d   S td|j W n
 tjyq   Y nw t||}|d	krt|I dH  qW d   |S 1 sw   Y  |S )a  
    Wait for an endpoint to become available before starting benchmarks.

    Args:
        request_func: The async request function to call
        test_input: The RequestFuncInput to test with
        timeout_seconds: Maximum time to wait in seconds (default: 10 minutes)
        retry_interval: Time between retries in seconds (default: 5 seconds)

    Returns:
        RequestFuncOutput: The successful response

    Raises:
        ValueError: If the endpoint doesn't become available within the timeout
    F)successz%Waiting for endpoint to become up in z secondsz7{desc} |{bar}| {elapsed} elapsed, {remaining} remainings)total
bar_formatunitTr   )request_func_inputr   Nz!Endpoint is not ready. Error='%s')timeperf_counterr   printr   minnupdaterefreshcloser   loggerwarningerroraiohttpClientConnectorErrorasynciosleep)r
   r   r   r   r   deadlineoutputpbar	remainingelapsedupdate_amountsleep_duration r,   ^/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/vllm/benchmarks/lib/ready_checker.pywait_for_endpoint   sP   


	
""r.   )r   r	   )__doc__r#   r   r!   tqdm.asyncior   vllm.loggerr   endpoint_request_funcr   r   r   __name__r   ClientSessionintr.   r,   r,   r,   r-   <module>   s.   