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
|
||||
pg_host: str = "pg.betelgeusebytes.io"
|
||||
pg_port: int = 5432
|
||||
pg_dbname: str = "REPLACE_ME"
|
||||
pg_user: str = "REPLACE_ME"
|
||||
pg_password: str = "REPLACE_ME"
|
||||
pg_dbname: str = "hadith_db4"
|
||||
pg_user: str = "hadith_ingest"
|
||||
pg_password: str = "hadith_ingest"
|
||||
pg_sslmode: str = "require"
|
||||
|
||||
# Neo4j
|
||||
|
|
@ -21,8 +21,8 @@ class Settings(BaseSettings):
|
|||
neo4j_password: str = "NEO4J-PASS"
|
||||
|
||||
# Qdrant
|
||||
qdrant_host: str = "qdrant.vector.svc.cluster.local"
|
||||
qdrant_port: int = 6333
|
||||
qdrant_host: str = "vector.betelgeusebytes.io"
|
||||
qdrant_port: int = 443
|
||||
qdrant_collection: str = "hadiths"
|
||||
|
||||
# Elasticsearch
|
||||
|
|
|
|||
|
|
@ -27,40 +27,56 @@ class Database:
|
|||
settings = get_settings()
|
||||
|
||||
# PostgreSQL connection pool
|
||||
self.pg_pool = psycopg2.pool.ThreadedConnectionPool(
|
||||
minconn=2,
|
||||
maxconn=10,
|
||||
host=settings.pg_host,
|
||||
port=settings.pg_port,
|
||||
dbname=settings.pg_dbname,
|
||||
user=settings.pg_user,
|
||||
password=settings.pg_password,
|
||||
sslmode=settings.pg_sslmode,
|
||||
)
|
||||
print(f"✅ PostgreSQL pool created ({settings.pg_host})")
|
||||
try:
|
||||
self.pg_pool = psycopg2.pool.ThreadedConnectionPool(
|
||||
minconn=2,
|
||||
maxconn=10,
|
||||
host=settings.pg_host,
|
||||
port=settings.pg_port,
|
||||
dbname=settings.pg_dbname,
|
||||
user=settings.pg_user,
|
||||
password=settings.pg_password,
|
||||
sslmode=settings.pg_sslmode,
|
||||
)
|
||||
print(f"✅ PostgreSQL pool created ({settings.pg_host})")
|
||||
except Exception as e:
|
||||
print(f"⚠️ PostgreSQL failed: {e}")
|
||||
|
||||
# Neo4j
|
||||
self.neo4j_driver = GraphDatabase.driver(
|
||||
settings.neo4j_uri,
|
||||
auth=(settings.neo4j_user, settings.neo4j_password),
|
||||
)
|
||||
self.neo4j_driver.verify_connectivity()
|
||||
print(f"✅ Neo4j connected ({settings.neo4j_uri})")
|
||||
try:
|
||||
self.neo4j_driver = GraphDatabase.driver(
|
||||
settings.neo4j_uri,
|
||||
auth=(settings.neo4j_user, settings.neo4j_password),
|
||||
)
|
||||
self.neo4j_driver.verify_connectivity()
|
||||
print(f"✅ Neo4j connected ({settings.neo4j_uri})")
|
||||
except Exception as e:
|
||||
print(f"⚠️ Neo4j failed: {e}")
|
||||
|
||||
# Qdrant
|
||||
self.qdrant = QdrantClient(
|
||||
host=settings.qdrant_host,
|
||||
port=settings.qdrant_port,
|
||||
)
|
||||
collections = self.qdrant.get_collections()
|
||||
print(f"✅ Qdrant connected ({settings.qdrant_host}, {len(collections.collections)} collections)")
|
||||
try:
|
||||
self.qdrant = QdrantClient(
|
||||
host=settings.qdrant_host,
|
||||
port=settings.qdrant_port,
|
||||
timeout=5,
|
||||
)
|
||||
collections = self.qdrant.get_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
|
||||
self.es = Elasticsearch(settings.es_host)
|
||||
if self.es.ping():
|
||||
print(f"✅ Elasticsearch connected ({settings.es_host})")
|
||||
else:
|
||||
print(f"⚠️ Elasticsearch ping failed ({settings.es_host})")
|
||||
try:
|
||||
self.es = Elasticsearch(settings.es_host, request_timeout=5)
|
||||
if self.es.ping():
|
||||
print(f"✅ Elasticsearch connected ({settings.es_host})")
|
||||
else:
|
||||
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
|
||||
self.http_client = httpx.AsyncClient(timeout=30.0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue