fix: Enhance database connection handling with error logging and default values
This commit is contained in:
parent
439405dead
commit
6ab8988cb6
|
|
@ -10,9 +10,9 @@ class Settings(BaseSettings):
|
||||||
# PostgreSQL
|
# PostgreSQL
|
||||||
pg_host: str = "pg.betelgeusebytes.io"
|
pg_host: str = "pg.betelgeusebytes.io"
|
||||||
pg_port: int = 5432
|
pg_port: int = 5432
|
||||||
pg_dbname: str = "REPLACE_ME"
|
pg_dbname: str = "hadith_db4"
|
||||||
pg_user: str = "REPLACE_ME"
|
pg_user: str = "hadith_ingest"
|
||||||
pg_password: str = "REPLACE_ME"
|
pg_password: str = "hadith_ingest"
|
||||||
pg_sslmode: str = "require"
|
pg_sslmode: str = "require"
|
||||||
|
|
||||||
# Neo4j
|
# Neo4j
|
||||||
|
|
@ -21,8 +21,8 @@ class Settings(BaseSettings):
|
||||||
neo4j_password: str = "NEO4J-PASS"
|
neo4j_password: str = "NEO4J-PASS"
|
||||||
|
|
||||||
# Qdrant
|
# Qdrant
|
||||||
qdrant_host: str = "qdrant.vector.svc.cluster.local"
|
qdrant_host: str = "vector.betelgeusebytes.io"
|
||||||
qdrant_port: int = 6333
|
qdrant_port: int = 443
|
||||||
qdrant_collection: str = "hadiths"
|
qdrant_collection: str = "hadiths"
|
||||||
|
|
||||||
# Elasticsearch
|
# Elasticsearch
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ class Database:
|
||||||
settings = get_settings()
|
settings = get_settings()
|
||||||
|
|
||||||
# PostgreSQL connection pool
|
# PostgreSQL connection pool
|
||||||
|
try:
|
||||||
self.pg_pool = psycopg2.pool.ThreadedConnectionPool(
|
self.pg_pool = psycopg2.pool.ThreadedConnectionPool(
|
||||||
minconn=2,
|
minconn=2,
|
||||||
maxconn=10,
|
maxconn=10,
|
||||||
|
|
@ -38,29 +39,44 @@ class Database:
|
||||||
sslmode=settings.pg_sslmode,
|
sslmode=settings.pg_sslmode,
|
||||||
)
|
)
|
||||||
print(f"✅ PostgreSQL pool created ({settings.pg_host})")
|
print(f"✅ PostgreSQL pool created ({settings.pg_host})")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ PostgreSQL failed: {e}")
|
||||||
|
|
||||||
# Neo4j
|
# Neo4j
|
||||||
|
try:
|
||||||
self.neo4j_driver = GraphDatabase.driver(
|
self.neo4j_driver = GraphDatabase.driver(
|
||||||
settings.neo4j_uri,
|
settings.neo4j_uri,
|
||||||
auth=(settings.neo4j_user, settings.neo4j_password),
|
auth=(settings.neo4j_user, settings.neo4j_password),
|
||||||
)
|
)
|
||||||
self.neo4j_driver.verify_connectivity()
|
self.neo4j_driver.verify_connectivity()
|
||||||
print(f"✅ Neo4j connected ({settings.neo4j_uri})")
|
print(f"✅ Neo4j connected ({settings.neo4j_uri})")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Neo4j failed: {e}")
|
||||||
|
|
||||||
# Qdrant
|
# Qdrant
|
||||||
|
try:
|
||||||
self.qdrant = QdrantClient(
|
self.qdrant = QdrantClient(
|
||||||
host=settings.qdrant_host,
|
host=settings.qdrant_host,
|
||||||
port=settings.qdrant_port,
|
port=settings.qdrant_port,
|
||||||
|
timeout=5,
|
||||||
)
|
)
|
||||||
collections = self.qdrant.get_collections()
|
collections = self.qdrant.get_collections()
|
||||||
print(f"✅ Qdrant connected ({settings.qdrant_host}, {len(collections.collections)} collections)")
|
print(f"✅ Qdrant connected ({settings.qdrant_host}, {len(collections.collections)} collections)")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Qdrant unavailable: {e}")
|
||||||
|
self.qdrant = None
|
||||||
|
|
||||||
# Elasticsearch
|
# Elasticsearch
|
||||||
self.es = Elasticsearch(settings.es_host)
|
try:
|
||||||
|
self.es = Elasticsearch(settings.es_host, request_timeout=5)
|
||||||
if self.es.ping():
|
if self.es.ping():
|
||||||
print(f"✅ Elasticsearch connected ({settings.es_host})")
|
print(f"✅ Elasticsearch connected ({settings.es_host})")
|
||||||
else:
|
else:
|
||||||
print(f"⚠️ Elasticsearch ping failed ({settings.es_host})")
|
print(f"⚠️ Elasticsearch ping failed ({settings.es_host})")
|
||||||
|
self.es = None
|
||||||
|
except Exception as e:
|
||||||
|
print(f"⚠️ Elasticsearch unavailable: {e}")
|
||||||
|
self.es = None
|
||||||
|
|
||||||
# HTTP client for TEI embedding requests
|
# HTTP client for TEI embedding requests
|
||||||
self.http_client = httpx.AsyncClient(timeout=30.0)
|
self.http_client = httpx.AsyncClient(timeout=30.0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue