deal db session in celery worker (#17549)
This commit is contained in:
parent
da7f8ad936
commit
c8145ce581
26 changed files with 104 additions and 25 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue