fix close session twice. (#24917)
Signed-off-by: zhanluxianshen <zhanluxianshen@163.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -27,6 +27,7 @@ def duplicate_document_indexing_task(dataset_id: str, document_ids: list):
|
|||||||
documents = []
|
documents = []
|
||||||
start_at = time.perf_counter()
|
start_at = time.perf_counter()
|
||||||
|
|
||||||
|
try:
|
||||||
dataset = db.session.query(Dataset).where(Dataset.id == dataset_id).first()
|
dataset = db.session.query(Dataset).where(Dataset.id == dataset_id).first()
|
||||||
if dataset is None:
|
if dataset is None:
|
||||||
logger.info(click.style(f"Dataset not found: {dataset_id}", fg="red"))
|
logger.info(click.style(f"Dataset not found: {dataset_id}", fg="red"))
|
||||||
@@ -52,7 +53,9 @@ def duplicate_document_indexing_task(dataset_id: str, document_ids: list):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
for document_id in document_ids:
|
for document_id in document_ids:
|
||||||
document = (
|
document = (
|
||||||
db.session.query(Document).where(Document.id == document_id, Document.dataset_id == dataset_id).first()
|
db.session.query(Document)
|
||||||
|
.where(Document.id == document_id, Document.dataset_id == dataset_id)
|
||||||
|
.first()
|
||||||
)
|
)
|
||||||
if document:
|
if document:
|
||||||
document.indexing_status = "error"
|
document.indexing_status = "error"
|
||||||
@@ -61,8 +64,6 @@ def duplicate_document_indexing_task(dataset_id: str, document_ids: list):
|
|||||||
db.session.add(document)
|
db.session.add(document)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return
|
return
|
||||||
finally:
|
|
||||||
db.session.close()
|
|
||||||
|
|
||||||
for document_id in document_ids:
|
for document_id in document_ids:
|
||||||
logger.info(click.style(f"Start process document: {document_id}", fg="green"))
|
logger.info(click.style(f"Start process document: {document_id}", fg="green"))
|
||||||
@@ -93,7 +94,6 @@ def duplicate_document_indexing_task(dataset_id: str, document_ids: list):
|
|||||||
db.session.add(document)
|
db.session.add(document)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
try:
|
|
||||||
indexing_runner = IndexingRunner()
|
indexing_runner = IndexingRunner()
|
||||||
indexing_runner.run(documents)
|
indexing_runner.run(documents)
|
||||||
end_at = time.perf_counter()
|
end_at = time.perf_counter()
|
||||||
|
Reference in New Issue
Block a user