Add initial project
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
"""Health service for business logic."""
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import text
|
||||
|
||||
|
||||
class HealthService:
|
||||
"""Service for health check operations."""
|
||||
|
||||
@staticmethod
|
||||
def check_database(db: Session) -> bool:
|
||||
"""Check if database connection is healthy."""
|
||||
try:
|
||||
db.execute(text("SELECT 1"))
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def get_health_status(db: Session) -> dict:
|
||||
"""Get the health status of the application."""
|
||||
db_healthy = HealthService.check_database(db)
|
||||
|
||||
return {
|
||||
"status": "healthy" if db_healthy else "unhealthy",
|
||||
"database": "connected" if db_healthy else "disconnected"
|
||||
}
|
||||
Reference in New Issue
Block a user