o
    ưi                     @  sD   d Z ddlmZ ddlZddlZddlmZ dd	d
ZdddZdS )z{
Prometheus multiprocess directory cleanup utilities.

Wipes all .db files on startup so workers start with a clean slate.
    )annotationsN)verbose_proxy_logger	directorystrreturnNonec                 C  s   t  tj| d}d}|D ]*}zt| |d7 }W q ty8 } ztd| d|  W Y d}~qd}~ww |rHtd| d|   dS dS )	zGDelete all .db files in the directory. Called once before workers fork.z*.dbr      z'Failed to delete stale prometheus file z: NzPrometheus cleanup: wiped z stale .db files from )	globospathjoinremoveOSErrorr   warninginfo)r   filesZdeletedfilepathe r   W/home/app/Keep/.python/lib/python3.10/site-packages/litellm/proxy/prometheus_cleanup.pywipe_directory   s"   
r   
worker_pidintc              
   C  s|   t jdsdS zddlm} ||  td|  d W dS  ty= } zt	d|  d|  W Y d}~dS d}~ww )	zRRemove prometheus .db files for a dead worker. Called by gunicorn child_exit hook.ZPROMETHEUS_MULTIPROC_DIRNr   )multiprocessz"Prometheus cleanup: marked worker z as deadz!Failed to mark prometheus worker z
 as dead: )
r
   environgetZprometheus_clientr   Zmark_process_deadr   r   	Exceptionr   )r   r   r   r   r   r   mark_worker_exit!   s   


r   )r   r   r   r   )r   r   r   r   )	__doc__
__future__r   r	   r
   Zlitellm._loggingr   r   r   r   r   r   r   <module>   s    
