deal db session in celery worker (#17549)

This commit is contained in:
Jyong 2025-04-07 20:31:26 +08:00 • committed by GitHub
commit c8145ce581
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 104 additions and 25 deletions

View file

@ -27,6 +27,7 @@ def document_indexing_task(dataset_id: str, document_ids: list):
dataset = db.session.query(Dataset).filter(Dataset.id == dataset_id).first()
if not dataset:
logging.info(click.style("Dataset is not found: {}".format(dataset_id), fg="yellow"))
db.session.close()
return
# check document limit
features = FeatureService.get_features(dataset.tenant_id)
@ -55,6 +56,7 @@ def document_indexing_task(dataset_id: str, document_ids: list):
document.stopped_at = datetime.datetime.now(datetime.UTC).replace(tzinfo=None)
db.session.add(document)
db.session.commit()
db.session.close()
return
for document_id in document_ids:
@ -80,3 +82,5 @@ def document_indexing_task(dataset_id: str, document_ids: list):
logging.info(click.style(str(ex), fg="yellow"))
except Exception:
pass
finally:
db.session.close()