search-fix, devstart-fix, cache-fix, logs-less
Some checks failed
Deploy on push / deploy (push) Failing after 5s

This commit is contained in:
2025-07-31 19:12:21 +03:00
parent e7230ba63c
commit 809bda2b56
6 changed files with 60 additions and 21 deletions

View File

@@ -126,23 +126,34 @@ def get_json_builder() -> tuple[Any, Any, Any]:
json_builder, json_array_builder, json_cast = get_json_builder()
def create_table_if_not_exists(connection_or_engine: Connection | Engine, model_cls: Type[DeclarativeBase]) -> None:
def create_table_if_not_exists(
connection_or_engine_or_session: Connection | Engine | Session, model_cls: Type[DeclarativeBase]
) -> None:
"""Creates table for the given model if it doesn't exist"""
# If an Engine is passed, get a connection from it
connection = connection_or_engine.connect() if isinstance(connection_or_engine, Engine) else connection_or_engine
# Handle different input types
if isinstance(connection_or_engine_or_session, Session):
# Use session's bind
connection = connection_or_engine_or_session.get_bind()
should_close = False
elif isinstance(connection_or_engine_or_session, Engine):
# Get a connection from engine
connection = connection_or_engine_or_session.connect()
should_close = True
else:
# Already a connection
connection = connection_or_engine_or_session
should_close = False
try:
inspector = inspect(connection)
if not inspector.has_table(model_cls.__tablename__):
# Use SQLAlchemy's built-in table creation instead of manual SQL generation
from sqlalchemy.schema import CreateTable
create_stmt = CreateTable(model_cls.__table__) # type: ignore[arg-type]
connection.execute(create_stmt)
model_cls.__table__.create(bind=connection, checkfirst=False)
logger.info(f"Created table: {model_cls.__tablename__}")
finally:
# If we created a connection from an Engine, close it
if isinstance(connection_or_engine, Engine):
# Close connection only if we created it
if should_close:
connection.close()

View File

@@ -189,10 +189,22 @@ class SearchCache:
class SearchService:
def __init__(self) -> None:
logger.info(f"Initializing search service with URL: {TXTAI_SERVICE_URL}")
self.available = SEARCH_ENABLED
# Проверяем валидность URL
if not TXTAI_SERVICE_URL or not TXTAI_SERVICE_URL.startswith(("http://", "https://")):
self.available = False
logger.info("Search disabled (invalid TXTAI_SERVICE_URL)")
else:
self.available = SEARCH_ENABLED
# Use different timeout settings for indexing and search requests
self.client = AsyncClient(timeout=30.0, base_url=TXTAI_SERVICE_URL)
self.index_client = AsyncClient(timeout=120.0, base_url=TXTAI_SERVICE_URL)
if self.available:
self.client = AsyncClient(timeout=30.0, base_url=TXTAI_SERVICE_URL)
self.index_client = AsyncClient(timeout=120.0, base_url=TXTAI_SERVICE_URL)
else:
self.client = None
self.index_client = None
# Initialize search cache
self.cache = SearchCache() if SEARCH_CACHE_ENABLED else None
@@ -205,7 +217,7 @@ class SearchService:
async def info(self) -> dict:
"""Return information about search service"""
if not self.available:
if not self.available or not self.client:
return {"status": "disabled"}
try:
response: Response = await self.client.get("/info")