Spaces:
Running

microfunnel-api / backend /scripts /health_check.py
axeronis
feat: Unified AI Brain 2.0 (Merged Knowledge Base & Persona, Removed /knowledge routes)
20ee727
Raw History Blame Contribute Delete
2.68 kB
import asyncio
import sys
import os
from sqlalchemy import text
# Add backend to path
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from app.core.database import get_async_session
from app.services.cache_service import cache_service
from app.services.google_calendar import get_google_calendar_service
from app.worker import celery_app
from app.core.config import settings
async def check_db():
print("\nπŸ” Checking Database...")
try:
async for session in get_async_session():
result = await session.execute(text("SELECT 1"))
print(f"βœ… Database connected. Result: {result.scalar()}")
# Check pgvector extension
try:
await session.execute(text("CREATE EXTENSION IF NOT EXISTS vector"))
print("βœ… pgvector extension verified.")
except Exception as e:
print(f"⚠️ pgvector check warning: {e}")
break
except Exception as e:
print(f"❌ Database connection failed: {e}")
async def check_redis():
print("\nπŸ” Checking Redis Cache...")
try:
await cache_service.set("health_check", "ok", ttl=10)
val = await cache_service.get("health_check")
if val == "ok":
mode = "Redis" if cache_service.use_redis else "Memory Fallback"
print(f"βœ… Cache working. Mode: {mode}")
else:
print("❌ Cache set/get mismatch.")
except Exception as e:
print(f"❌ Cache check failed: {e}")
def check_celery():
print("\nπŸ” Checking Celery Config...")
try:
print(f"βœ… Broker URL: {celery_app.conf.broker_url}")
print(f"βœ… Registered Tasks: {list(celery_app.tasks.keys())}")
except Exception as e:
print(f"❌ Celery check failed: {e}")
def check_google_calendar():
print("\nπŸ” Checking Google Calendar Service...")
try:
service = get_google_calendar_service()
# Mock tenant ID
from uuid import uuid4
url = service.get_auth_url(uuid4())
if "accounts.google.com" in url:
print("βœ… Auth URL generation working.")
else:
print("❌ Auth URL unexpected format.")
except Exception as e:
print(f"❌ Google Calendar check failed: {e}")
async def main():
print("πŸ₯ STARTING SYSTEM HEALTH CHECK")
await check_db()
await check_redis()
check_celery()
check_google_calendar()
print("\n🏁 Health Check Complete.")
if __name__ == "__main__":
if sys.platform == 'win32':
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
asyncio.run(main())