
    KCj                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ  e       Z e       Zej                  d      d	efd
       Zej                  d      d	efd       Zy)u@  
Health check endpoints.

Two distinct checks, both standard practice in production:
- /health/live  — "is the process alive at all". Used by systemd/Docker
  to decide whether to restart the process. Must be cheap and never
  depend on external services (DB/Redis) — if Postgres is briefly down,
  the process itself is still alive and should NOT be restarted for that.
- /health/ready — "is this instance able to actually serve requests".
  Used by Nginx/load balancer to decide whether to route traffic here.
  Checks DB and Redis connectivity and model load status.
    )	APIRouter)get_settings)check_db_connection)model_registry)cache_service)reference_dataz/health/livereturnc                  0   K   dt         j                  dS w)Nalive)statusversion)settingsAPP_VERSION     HC:\Crop_Prediction\Backend\crop-ai-system\app\api\v1\endpoints\health.pylivenessr      s     (*>*>??s   z/health/readyc                  (  K   t                d {   } t        j                          d {   }t        j                  }t
        j                  }| xr |xr |}|rdnd| rdnd|rdnd|rdnd|rdndd|rt        j                  dS g dS 7 }7 cw)Nready	not_readyokfaileddegraded)databaseredis_cachemodels_loadedreference_data_loaded)r   checksloaded_models)r   r   health_checkr   is_readyr   _loadedloaded_model_keys)db_okredis_ok	models_okreference_okall_oks        r   	readinessr)      s     %''E"//11H''I!))L1y1\F $' %8#+4%.TH-9Tx	
 >G99	 	 MO	 	 (1s    BBBBA"BBN)__doc__fastapir   app.core.configr   app.db.sessionr   app.models_loader.registryr   app.services.cache_servicer   app.services.reference_datar   routerr   getdictr   r)   r   r   r   <module>r4      sw     ( . 5 4 6	> N@ @ @ O  r   