fix(zopk): Thread-safe DB session and connection pool for gthread workers
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Create separate SessionLocal() in run_search() thread instead of sharing main thread's session (SQLAlchemy sessions are not thread-safe). Increase connection pool_size to 10 with pool_pre_ping for gthread worker support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fae7bfa0b2
commit
c7a42c3766
@ -618,14 +618,16 @@ def api_zopk_search_news_stream():
|
||||
progress_queue.put((phase, message, current, total))
|
||||
|
||||
def run_search():
|
||||
search_db = SessionLocal()
|
||||
try:
|
||||
service = ZOPKNewsService(db)
|
||||
service = ZOPKNewsService(search_db)
|
||||
result_holder[0] = service.search_all_sources(
|
||||
query, user_id=user_id, progress_callback=on_progress
|
||||
)
|
||||
except Exception as e:
|
||||
error_holder[0] = e
|
||||
finally:
|
||||
search_db.close()
|
||||
progress_queue.put(None) # sentinel
|
||||
|
||||
thread = threading.Thread(target=run_search, daemon=True)
|
||||
|
||||
@ -253,7 +253,7 @@ JSONB = JSONBType
|
||||
|
||||
|
||||
# Create engine
|
||||
engine = create_engine(DATABASE_URL, echo=False)
|
||||
engine = create_engine(DATABASE_URL, echo=False, pool_size=10, pool_pre_ping=True)
|
||||
SessionLocal = sessionmaker(bind=engine)
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user