23 lines
787 B
Python
23 lines
787 B
Python
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from dotenv import load_dotenv
|
|
import os
|
|
|
|
load_dotenv()
|
|
|
|
MONGODB_URI = os.getenv("MONGODB_URI", "mongodb://localhost:27017")
|
|
MONGODB_DBNAME = os.getenv("MONGODB_DBNAME", "agenthub_db")
|
|
|
|
client = AsyncIOMotorClient(MONGODB_URI)
|
|
db = client[MONGODB_DBNAME]
|
|
users_collection = db.get_collection("users")
|
|
agents_collection = db.get_collection("agents")
|
|
agent_usage_collection = db.get_collection("agent_usage")
|
|
|
|
async def check_database_health():
|
|
"""Check MongoDB connection health"""
|
|
try:
|
|
# Attempt to ping the database
|
|
await client.admin.command('ping')
|
|
return {"status": "connected", "healthy": True}
|
|
except Exception as e:
|
|
return {"status": "disconnected", "healthy": False, "error": str(e)}
|