From 389e79d3b271835db4eb2bc4d415c723cb1984a3 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 16 Mar 2024 14:14:17 -0700 Subject: [PATCH] (fix) improve /health/readiness under high load --- litellm/proxy/proxy_server.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index b482e472e..1b68e489d 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -7280,10 +7280,8 @@ def _db_health_readiness_check(): # Note - Intentionally don't try/except this so it raises an exception when it fails # if timedelta is less than 2 minutes return DB Status - if ( - db_health_cache["status"] != "unknown" - and db_health_cache["last_updated"] + timedelta(minutes=2) > datetime.now() - ): + time_diff = datetime.now() - db_health_cache["last_updated"] + if db_health_cache["status"] != "unknown" and time_diff < timedelta(minutes=2): return db_health_cache prisma_client.health_check() db_health_cache = {"status": "connected", "last_updated": datetime.now()}