25 lines
916 B
Python
Executable File
25 lines
916 B
Python
Executable File
from common.config.app_settings import app_settings
|
|
from beanie import init_beanie
|
|
from motor.motor_asyncio import AsyncIOMotorClient
|
|
from database.mongo.models import mongo_models
|
|
import asyncio
|
|
from common.probes import ProbeResult
|
|
|
|
client = AsyncIOMotorClient(app_settings.MONGODB_URI, serverSelectionTimeoutMS=60000)
|
|
|
|
async def check_database_initialized() -> ProbeResult:
|
|
try:
|
|
await asyncio.wait_for(client.server_info(), timeout=5)
|
|
return ProbeResult(success=True, message="service has been initialized and ready to serve")
|
|
except Exception:
|
|
return ProbeResult(success=False, message="service is not initialized yet", data={"error": "database is not ready"})
|
|
|
|
class MongoDriver:
|
|
def __init__(self):
|
|
pass
|
|
|
|
async def initiate_database(self):
|
|
await init_beanie(
|
|
database=client[app_settings.MONGODB_NAME], document_models=mongo_models
|
|
)
|