deal db session in celery worker (#17549)

This commit is contained in:
Jyong
2025-04-07 20:31:26 +08:00
committed by GitHub
parent da7f8ad936
commit c8145ce581
26 changed files with 104 additions and 25 deletions

View File

@@ -5,7 +5,6 @@ from typing import Optional
import click
from celery import shared_task # type: ignore
from werkzeug.exceptions import NotFound
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
from core.rag.models.document import Document
@@ -27,7 +26,9 @@ def create_segment_to_index_task(segment_id: str, keywords: Optional[list[str]]
segment = db.session.query(DocumentSegment).filter(DocumentSegment.id == segment_id).first()
if not segment:
raise NotFound("Segment not found")
logging.info(click.style("Segment not found: {}".format(segment_id), fg="red"))
db.session.close()
return
if segment.status != "waiting":
return
@@ -93,3 +94,4 @@ def create_segment_to_index_task(segment_id: str, keywords: Optional[list[str]]
db.session.commit()
finally:
redis_client.delete(indexing_cache_key)
db.session.close()