Refactored DocumentService to save document in the filesystem. Fixed docker application
This commit is contained in:
@@ -10,7 +10,7 @@ from typing import Optional
|
||||
from pymongo import MongoClient
|
||||
from pymongo.database import Database
|
||||
from pymongo.errors import ConnectionFailure, ServerSelectionTimeoutError
|
||||
|
||||
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
|
||||
from app.config.settings import get_mongodb_url, get_mongodb_database_name
|
||||
|
||||
# Global variables for singleton pattern
|
||||
@@ -18,7 +18,7 @@ _client: Optional[MongoClient] = None
|
||||
_database: Optional[Database] = None
|
||||
|
||||
|
||||
def create_mongodb_client() -> MongoClient:
|
||||
def create_mongodb_client() -> AsyncIOMotorClient:
|
||||
"""
|
||||
Create MongoDB client with connection validation.
|
||||
|
||||
@@ -32,7 +32,7 @@ def create_mongodb_client() -> MongoClient:
|
||||
|
||||
try:
|
||||
# Create client with short timeout for fail-fast behavior
|
||||
client = MongoClient(
|
||||
client = AsyncIOMotorClient(
|
||||
mongodb_url,
|
||||
serverSelectionTimeoutMS=5000, # 5 seconds timeout
|
||||
connectTimeoutMS=5000,
|
||||
@@ -107,6 +107,15 @@ def get_mongodb_client() -> Optional[MongoClient]:
|
||||
return _client
|
||||
|
||||
|
||||
def get_extra_args(session):
|
||||
# Build kwargs only if session is provided
|
||||
kwargs = {}
|
||||
if session is not None:
|
||||
kwargs["session"] = session
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
def test_database_connection() -> bool:
|
||||
"""
|
||||
Test if database connection is working.
|
||||
@@ -122,4 +131,4 @@ def test_database_connection() -> bool:
|
||||
db.command('ping')
|
||||
return True
|
||||
except Exception:
|
||||
return False
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user