Spaces:
Running
Running
axeronis
feat: Unified AI Brain 2.0 (Merged Knowledge Base & Persona, Removed /knowledge routes)
20ee727 Download backend/scripts/health_check.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 2.68 kB
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/scripts/health_check.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/scripts/health_check.py
-
curl -L -o health_check.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/scripts/health_check.py
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()) | |