Create Translation service health check

This commit is contained in:
2025-07-14 10:31:18 -05:00
parent dc5958a995
commit 627a474d50

View 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 Translation 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())