Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Deployment readiness check for Atlas analytics system | |
| """ | |
| import asyncio | |
| import os | |
| import sys | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| async def check_environment_variables(): | |
| """Check if all required environment variables are set""" | |
| print("π Environment Variables Check") | |
| print("=" * 40) | |
| required_vars = { | |
| "GOOGLE_API_KEY": "Google Gemini API", | |
| "BRAVE_API_KEY": "Brave Search API", | |
| "MONGODB_URL": "MongoDB Atlas connection", | |
| "MONGODB_DATABASE": "MongoDB database name" | |
| } | |
| all_set = True | |
| for var, description in required_vars.items(): | |
| value = os.getenv(var) | |
| if value: | |
| print(f"β {var}: Set ({description})") | |
| else: | |
| print(f"β {var}: Missing ({description})") | |
| all_set = False | |
| return all_set | |
| async def check_database_connection(): | |
| """Check MongoDB connection""" | |
| print("\nποΈ Database Connection Check") | |
| print("=" * 40) | |
| try: | |
| from analytics.database import test_connection | |
| connected = await test_connection() | |
| if connected: | |
| print("β MongoDB connection successful") | |
| return True | |
| else: | |
| print("β MongoDB connection failed") | |
| return False | |
| except Exception as e: | |
| print(f"β Database connection error: {e}") | |
| return False | |
| async def check_analytics_system(): | |
| """Check analytics system functionality""" | |
| print("\nπ Analytics System Check") | |
| print("=" * 40) | |
| try: | |
| # Test dashboard | |
| from analytics.dashboard import get_basic_stats | |
| stats = await get_basic_stats() | |
| if "error" in stats: | |
| print(f"β Dashboard error: {stats['error']}") | |
| return False | |
| else: | |
| print("β Dashboard working") | |
| print(f" Sessions: {stats.get('total_sessions', 0)}") | |
| print(f" Messages: {stats.get('total_messages', 0)}") | |
| # Test collectors | |
| from analytics.collectors import create_session | |
| test_session = await create_session(user_agent="Deployment Test") | |
| if test_session: | |
| print("β Session creation working") | |
| else: | |
| print("β Session creation failed") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f"β Analytics system error: {e}") | |
| return False | |
| async def check_dependencies(): | |
| """Check if all required packages are available""" | |
| print("\nπ¦ Dependencies Check") | |
| print("=" * 40) | |
| required_packages = [ | |
| ("fastapi", "FastAPI web framework"), | |
| ("motor", "MongoDB async driver"), | |
| ("google.generativeai", "Google Gemini API"), | |
| ("httpx", "HTTP client"), | |
| ("pydantic", "Data validation"), | |
| ("dotenv", "Environment variables") | |
| ] | |
| all_available = True | |
| for package, description in required_packages: | |
| try: | |
| __import__(package.replace("-", "_")) | |
| print(f"β {package}: Available ({description})") | |
| except ImportError: | |
| print(f"β {package}: Missing ({description})") | |
| all_available = False | |
| return all_available | |
| async def main(): | |
| """Run all deployment checks""" | |
| print("π Atlas Analytics Deployment Check") | |
| print("=" * 50) | |
| checks = [ | |
| ("Environment Variables", check_environment_variables()), | |
| ("Dependencies", check_dependencies()), | |
| ("Database Connection", check_database_connection()), | |
| ("Analytics System", check_analytics_system()) | |
| ] | |
| results = [] | |
| for name, check_coro in checks: | |
| try: | |
| result = await check_coro | |
| results.append((name, result)) | |
| except Exception as e: | |
| print(f"β {name} check failed: {e}") | |
| results.append((name, False)) | |
| # Summary | |
| print("\nπ Deployment Readiness Summary") | |
| print("=" * 50) | |
| all_passed = True | |
| for name, passed in results: | |
| status = "β PASS" if passed else "β FAIL" | |
| print(f"{status} {name}") | |
| if not passed: | |
| all_passed = False | |
| print("\n" + "=" * 50) | |
| if all_passed: | |
| print("π DEPLOYMENT READY: All checks passed!") | |
| print(" You can deploy the Atlas analytics system.") | |
| sys.exit(0) | |
| else: | |
| print("β οΈ DEPLOYMENT NOT READY: Some checks failed.") | |
| print(" Please fix the issues above before deploying.") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |