Skip to content

Commit 62c4127

Browse files
committed
limit session scope
1 parent b2c55eb commit 62c4127

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

backend/danswer/background/celery/tasks/indexing/tasks.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def connector_indexing_task(
489489
f"search_settings={search_settings_id}"
490490
)
491491

492-
attempt = None
492+
attempt_found = False
493493
n_final_progress: int | None = None
494494

495495
redis_connector = RedisConnector(tenant_id, cc_pair_id)
@@ -557,6 +557,7 @@ def connector_indexing_task(
557557
raise ValueError(
558558
f"Index attempt not found: index_attempt={index_attempt_id}"
559559
)
560+
attempt_found = True
560561

561562
cc_pair = get_connector_credential_pair_from_id(
562563
cc_pair_id=cc_pair_id,
@@ -576,42 +577,42 @@ def connector_indexing_task(
576577
f"Credential not found: cc_pair={cc_pair_id} credential={cc_pair.credential_id}"
577578
)
578579

579-
# define a callback class
580-
callback = RunIndexingCallback(
581-
redis_connector.stop.fence_key,
582-
redis_connector_index.generator_progress_key,
583-
lock,
584-
r,
585-
)
580+
# define a callback class
581+
callback = RunIndexingCallback(
582+
redis_connector.stop.fence_key,
583+
redis_connector_index.generator_progress_key,
584+
lock,
585+
r,
586+
)
586587

587-
logger.info(
588-
f"Indexing spawned task running entrypoint: attempt={index_attempt_id} "
589-
f"tenant={tenant_id} "
590-
f"cc_pair={cc_pair_id} "
591-
f"search_settings={search_settings_id}"
592-
)
588+
logger.info(
589+
f"Indexing spawned task running entrypoint: attempt={index_attempt_id} "
590+
f"tenant={tenant_id} "
591+
f"cc_pair={cc_pair_id} "
592+
f"search_settings={search_settings_id}"
593+
)
593594

594-
run_indexing_entrypoint(
595-
index_attempt_id,
596-
tenant_id,
597-
cc_pair_id,
598-
is_ee,
599-
callback=callback,
600-
)
595+
run_indexing_entrypoint(
596+
index_attempt_id,
597+
tenant_id,
598+
cc_pair_id,
599+
is_ee,
600+
callback=callback,
601+
)
601602

602-
# get back the total number of indexed docs and return it
603-
n_final_progress = redis_connector_index.get_progress()
604-
redis_connector_index.set_generator_complete(HTTPStatus.OK.value)
603+
# get back the total number of indexed docs and return it
604+
n_final_progress = redis_connector_index.get_progress()
605+
redis_connector_index.set_generator_complete(HTTPStatus.OK.value)
605606
except Exception as e:
606607
logger.exception(
607608
f"Indexing spawned task failed: attempt={index_attempt_id} "
608609
f"tenant={tenant_id} "
609610
f"cc_pair={cc_pair_id} "
610611
f"search_settings={search_settings_id}"
611612
)
612-
if attempt:
613+
if attempt_found:
613614
with get_session_with_tenant(tenant_id) as db_session:
614-
mark_attempt_failed(attempt, db_session, failure_reason=str(e))
615+
mark_attempt_failed(index_attempt_id, db_session, failure_reason=str(e))
615616

616617
redis_connector_index.reset()
617618
raise e

backend/danswer/background/celery/tasks/vespa/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def monitor_ccpair_indexing_taskset(
610610
index_attempt = get_index_attempt(db_session, payload.index_attempt_id)
611611
if index_attempt:
612612
mark_attempt_failed(
613-
index_attempt=index_attempt,
613+
index_attempt_id=payload.index_attempt_id,
614614
db_session=db_session,
615615
failure_reason="Connector indexing aborted or exceptioned.",
616616
)
@@ -696,7 +696,7 @@ def monitor_vespa_sync(self: Task, tenant_id: str | None) -> bool:
696696
a.connector_credential_pair_id, a.search_settings_id
697697
)
698698
):
699-
mark_attempt_failed(a, db_session, failure_reason=failure_reason)
699+
mark_attempt_failed(a.id, db_session, failure_reason=failure_reason)
700700

701701
lock_beat.reacquire()
702702
if r.exists(RedisConnectorCredentialPair.get_fence_key()):

backend/danswer/background/indexing/run_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ def _run_indexing(
337337
or index_attempt.status != IndexingStatus.IN_PROGRESS
338338
):
339339
mark_attempt_failed(
340-
index_attempt,
340+
index_attempt.id,
341341
db_session,
342342
failure_reason=str(e),
343343
full_exception_trace=traceback.format_exc(),
@@ -372,7 +372,7 @@ def _run_indexing(
372372
and index_attempt_md.num_exceptions >= batch_num
373373
):
374374
mark_attempt_failed(
375-
index_attempt,
375+
index_attempt.id,
376376
db_session,
377377
failure_reason="All batches exceptioned.",
378378
)

backend/danswer/db/index_attempt.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,15 @@ def mark_attempt_partially_succeeded(
219219

220220

221221
def mark_attempt_failed(
222-
index_attempt: IndexAttempt,
222+
index_attempt_id: int,
223223
db_session: Session,
224224
failure_reason: str = "Unknown",
225225
full_exception_trace: str | None = None,
226226
) -> None:
227227
try:
228228
attempt = db_session.execute(
229229
select(IndexAttempt)
230-
.where(IndexAttempt.id == index_attempt.id)
230+
.where(IndexAttempt.id == index_attempt_id)
231231
.with_for_update()
232232
).scalar_one()
233233

0 commit comments

Comments
 (0)