NEXAS commited on
Commit
1639b8b
·
verified ·
1 Parent(s): 10a6234

Rename extras/health.py to health.py

Browse files
Files changed (2) hide show
  1. extras/health.py +0 -70
  2. health.py +82 -0
extras/health.py DELETED
@@ -1,70 +0,0 @@
1
- """
2
- Health Check Endpoint
3
- Monitors system health and dependencies
4
- """
5
- from datetime import datetime
6
- from db import Database
7
- from cache import cache
8
- import os
9
-
10
- def check_database():
11
- """Check if database is accessible"""
12
- try:
13
- db = Database()
14
- # Try a simple operation
15
- if db.client:
16
- # Test query
17
- db.client.table("users").select("*").limit(1).execute()
18
- return True
19
- return False
20
- except Exception as e:
21
- print(f"Database health check failed: {e}")
22
- return False
23
-
24
- def check_redis():
25
- """Check if Redis is accessible"""
26
- try:
27
- if not cache.enabled:
28
- return False
29
- # Try to set and get a test value
30
- cache.set("health_check", "ok", ttl=10)
31
- result = cache.get("health_check")
32
- return result == "ok"
33
- except Exception as e:
34
- print(f"Redis health check failed: {e}")
35
- return False
36
-
37
- def check_livekit():
38
- """Check if LiveKit credentials are configured"""
39
- return all([
40
- os.getenv("LIVEKIT_URL"),
41
- os.getenv("LIVEKIT_API_KEY"),
42
- os.getenv("LIVEKIT_API_SECRET")
43
- ])
44
-
45
- def check_llm():
46
- """Check if LLM API keys are configured"""
47
- return os.getenv("GROQ_API_KEY") is not None
48
-
49
- def check_tts():
50
- """Check if TTS API keys are configured"""
51
- return os.getenv("DEEPGRAM_API_KEY") is not None
52
-
53
- def get_health_status():
54
- """Get comprehensive health status"""
55
- checks = {
56
- "database": check_database(),
57
- "redis": check_redis(),
58
- "livekit": check_livekit(),
59
- "llm": check_llm(),
60
- "tts": check_tts()
61
- }
62
-
63
- all_healthy = all(checks.values())
64
-
65
- return {
66
- "status": "healthy" if all_healthy else "degraded",
67
- "timestamp": datetime.now().isoformat(),
68
- "checks": checks,
69
- "version": "1.0.0"
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
health.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from http.server import HTTPServer, BaseHTTPRequestHandler
2
+
3
+ class HealthHandler(BaseHTTPRequestHandler):
4
+ def do_GET(self):
5
+ self.send_response(200)
6
+ self.end_headers()
7
+ self.wfile.write(b"OK")
8
+
9
+ HTTPServer(("0.0.0.0", 7860), HealthHandler).serve_forever()
10
+
11
+
12
+
13
+ # """
14
+ # Health Check Endpoint
15
+ # Monitors system health and dependencies
16
+ # """
17
+ # from datetime import datetime
18
+ # from db import Database
19
+ # from cache import cache
20
+ # import os
21
+
22
+ # def check_database():
23
+ # """Check if database is accessible"""
24
+ # try:
25
+ # db = Database()
26
+ # # Try a simple operation
27
+ # if db.client:
28
+ # # Test query
29
+ # db.client.table("users").select("*").limit(1).execute()
30
+ # return True
31
+ # return False
32
+ # except Exception as e:
33
+ # print(f"Database health check failed: {e}")
34
+ # return False
35
+
36
+ # def check_redis():
37
+ # """Check if Redis is accessible"""
38
+ # try:
39
+ # if not cache.enabled:
40
+ # return False
41
+ # # Try to set and get a test value
42
+ # cache.set("health_check", "ok", ttl=10)
43
+ # result = cache.get("health_check")
44
+ # return result == "ok"
45
+ # except Exception as e:
46
+ # print(f"Redis health check failed: {e}")
47
+ # return False
48
+
49
+ # def check_livekit():
50
+ # """Check if LiveKit credentials are configured"""
51
+ # return all([
52
+ # os.getenv("LIVEKIT_URL"),
53
+ # os.getenv("LIVEKIT_API_KEY"),
54
+ # os.getenv("LIVEKIT_API_SECRET")
55
+ # ])
56
+
57
+ # def check_llm():
58
+ # """Check if LLM API keys are configured"""
59
+ # return os.getenv("GROQ_API_KEY") is not None
60
+
61
+ # def check_tts():
62
+ # """Check if TTS API keys are configured"""
63
+ # return os.getenv("DEEPGRAM_API_KEY") is not None
64
+
65
+ # def get_health_status():
66
+ # """Get comprehensive health status"""
67
+ # checks = {
68
+ # "database": check_database(),
69
+ # "redis": check_redis(),
70
+ # "livekit": check_livekit(),
71
+ # "llm": check_llm(),
72
+ # "tts": check_tts()
73
+ # }
74
+
75
+ # all_healthy = all(checks.values())
76
+
77
+ # return {
78
+ # "status": "healthy" if all_healthy else "degraded",
79
+ # "timestamp": datetime.now().isoformat(),
80
+ # "checks": checks,
81
+ # "version": "1.0.0"
82
+ # }