From 7057be6a88985c9bff31d3c15f1ee9aa5c61d53d Mon Sep 17 00:00:00 2001 From: rkuo-danswer Date: Wed, 24 Jul 2024 11:39:44 -0700 Subject: [PATCH] Bugfix/indexing progress (#1916) * mark in progress should always be committed * no_commit version of mark_attempt is not needed --- backend/danswer/background/indexing/run_indexing.py | 6 ++---- backend/danswer/db/index_attempt.py | 4 +++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/danswer/background/indexing/run_indexing.py b/backend/danswer/background/indexing/run_indexing.py index dd529cbf5d56..b7b025803e56 100644 --- a/backend/danswer/background/indexing/run_indexing.py +++ b/backend/danswer/background/indexing/run_indexing.py @@ -20,7 +20,7 @@ from danswer.db.connector_credential_pair import update_connector_credential_pai from danswer.db.engine import get_sqlalchemy_engine from danswer.db.index_attempt import get_index_attempt from danswer.db.index_attempt import mark_attempt_failed -from danswer.db.index_attempt import mark_attempt_in_progress__no_commit +from danswer.db.index_attempt import mark_attempt_in_progress from danswer.db.index_attempt import mark_attempt_succeeded from danswer.db.index_attempt import update_docs_indexed from danswer.db.models import IndexAttempt @@ -299,9 +299,7 @@ def _prepare_index_attempt(db_session: Session, index_attempt_id: int) -> IndexA ) # only commit once, to make sure this all happens in a single transaction - mark_attempt_in_progress__no_commit(attempt) - if attempt.embedding_model.status != IndexModelStatus.PRESENT: - db_session.commit() + mark_attempt_in_progress(attempt, db_session) return attempt diff --git a/backend/danswer/db/index_attempt.py b/backend/danswer/db/index_attempt.py index 51c41c719865..91b13cfd6cca 100644 --- a/backend/danswer/db/index_attempt.py +++ b/backend/danswer/db/index_attempt.py @@ -75,11 +75,13 @@ def get_not_started_index_attempts(db_session: Session) -> list[IndexAttempt]: return list(new_attempts.all()) -def mark_attempt_in_progress__no_commit( +def mark_attempt_in_progress( index_attempt: IndexAttempt, + db_session: Session, ) -> None: index_attempt.status = IndexingStatus.IN_PROGRESS index_attempt.time_started = index_attempt.time_started or func.now() # type: ignore + db_session.commit() def mark_attempt_succeeded(