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
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue