Create Whisper service health check
This commit is contained in:
35
services/whisper-service/src/healthcheck.py
Normal file
35
services/whisper-service/src/healthcheck.py
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import os
|
||||||
|
import asyncio
|
||||||
|
import requests
|
||||||
|
import redis.asyncio as redis
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
|
async def health_check():
|
||||||
|
"""Health check for Whisper service"""
|
||||||
|
try:
|
||||||
|
# Test API endpoint
|
||||||
|
response = requests.get("http://localhost:8000/health", timeout=10)
|
||||||
|
if response.status_code != 200:
|
||||||
|
raise Exception(f"API health check failed: {response.status_code}")
|
||||||
|
|
||||||
|
# Test Redis connection
|
||||||
|
redis_client = redis.from_url(os.getenv('REDIS_URL', 'redis://redis:6379'))
|
||||||
|
await redis_client.ping()
|
||||||
|
await redis_client.close()
|
||||||
|
|
||||||
|
# Test PostgreSQL connection
|
||||||
|
pg_conn = psycopg2.connect(os.getenv('POSTGRES_URL'))
|
||||||
|
cursor = pg_conn.cursor()
|
||||||
|
cursor.execute('SELECT 1')
|
||||||
|
cursor.close()
|
||||||
|
pg_conn.close()
|
||||||
|
|
||||||
|
print("Health check passed")
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Health check failed: {e}")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
asyncio.run(health_check())
|
Reference in New Issue
Block a user