fmt
Some checks failed
Deploy on push / deploy (push) Failing after 36s

This commit is contained in:
2025-08-23 10:47:52 +03:00
parent d33e53933f
commit b4f683a7cc
12 changed files with 406 additions and 810 deletions

27
main.py
View File

@@ -22,7 +22,7 @@ from auth.oauth import oauth_callback, oauth_login
from cache.precache import precache_data
from cache.revalidator import revalidation_manager
from rbac import initialize_rbac
from services.search import check_search_service, initialize_search_index_background, search_service
from services.search import check_search_service, search_service
from services.viewed import ViewedStorage
from settings import DEV_SERVER_PID_FILE_NAME
from storage.redis import redis
@@ -188,7 +188,7 @@ async def dev_start() -> None:
# Глобальная переменная для background tasks
background_tasks = []
background_tasks: list[asyncio.Task] = []
@asynccontextmanager
@@ -210,24 +210,20 @@ async def lifespan(app: Starlette):
"""
try:
print("[lifespan] Starting application initialization")
# Запускаем миграции Alembic перед созданием таблиц
print("[lifespan] Running database migrations...")
try:
import subprocess
result = subprocess.run(
["alembic", "upgrade", "head"],
capture_output=True,
text=True,
cwd="/app"
)
result = subprocess.run(["alembic", "upgrade", "head"], check=False, capture_output=True, text=True, cwd="/app")
if result.returncode == 0:
print("[lifespan] Database migrations completed successfully")
else:
print(f"[lifespan] Warning: migrations failed: {result.stderr}")
except Exception as e:
print(f"[lifespan] Warning: could not run migrations: {e}")
create_all_tables()
# Инициализируем RBAC систему с dependency injection
@@ -244,14 +240,9 @@ async def lifespan(app: Starlette):
await dev_start()
print("[lifespan] Basic initialization complete")
# Add a delay before starting the intensive search indexing
print("[lifespan] Waiting for system stabilization before search indexing...")
await asyncio.sleep(1) # 1-second delay to let the system stabilize
# Start search indexing as a background task with lower priority
search_task = asyncio.create_task(initialize_search_index_background())
background_tasks.append(search_task)
# Не ждем завершения задачи, позволяем ей выполняться в фоне
# Search service is now handled by Muvera automatically
# No need for background indexing tasks
print("[lifespan] Search service initialized with Muvera")
yield
finally: