Skip to content

Commit 9207a23

Browse files
authored
Merge pull request #3756 from freelawproject/introduce-retries-for-update-by-query-requests-on-timeouts
2 parents 7a3b3c1 + 9ee7f0b commit 9207a23

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cl/search/tasks.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ def get_doc_from_es(
610610

611611
def handle_ubq_retries(
612612
self: Task,
613-
exc: ConnectionError | ConflictError,
613+
exc: ConnectionError | ConflictError | ConnectionTimeout,
614614
count_query=QuerySet | None,
615615
) -> None:
616616
"""Handles the retry logic for update_children_docs_by_query task based on
@@ -627,9 +627,9 @@ def handle_ubq_retries(
627627
if retry_count >= self.max_retries:
628628
raise exc
629629

630-
if isinstance(exc, ConnectionError) and count_query:
630+
if isinstance(exc, ConnectionError | ConnectionTimeout) and count_query:
631631
num_documents = count_query.count()
632-
estimated_time_ms = num_documents * 15 # 15ms per document
632+
estimated_time_ms = num_documents * 90 # 90ms per document
633633
# Convert ms to seconds
634634
estimated_delay_sec = round(estimated_time_ms / 1000)
635635
# Apply exponential backoff with jitter
@@ -693,6 +693,9 @@ def update_children_docs_by_query(
693693
parent_instance = get_instance_from_db(parent_instance_id, Docket)
694694
if not parent_instance:
695695
return
696+
count_query = RECAPDocument.objects.filter(
697+
docket_entry__docket_id=parent_instance_id
698+
)
696699
elif (
697700
es_document is OpinionDocument or es_document is OpinionClusterDocument
698701
):
@@ -704,10 +707,7 @@ def update_children_docs_by_query(
704707
)
705708
if not parent_instance:
706709
return
707-
708-
count_query = RECAPDocument.objects.filter(
709-
docket_entry__docket_id=parent_instance_id
710-
)
710+
count_query = Opinion.objects.filter(cluster_id=parent_instance_id)
711711

712712
if not main_doc:
713713
# Abort bulk update for a not supported document or non-existing parent
@@ -744,7 +744,7 @@ def update_children_docs_by_query(
744744
ubq = ubq.script(source=script_source, params=params)
745745
try:
746746
ubq.execute()
747-
except (ConnectionError, ConflictError) as exc:
747+
except (ConnectionError, ConflictError, ConnectionTimeout) as exc:
748748
handle_ubq_retries(self, exc, count_query=count_query)
749749

750750
if settings.ELASTICSEARCH_DSL_AUTO_REFRESH:

cl/settings/third_party/elasticsearch.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"ELASTICSEARCH_CA_CERT",
5858
default="/opt/courtlistener/docker/elastic/ca.crt",
5959
)
60-
ELASTICSEARCH_TIMEOUT = env("ELASTICSEARCH_TIMEOUT", default=200)
60+
ELASTICSEARCH_TIMEOUT = env("ELASTICSEARCH_TIMEOUT", default=3500)
6161

6262
base_connection_params = {
6363
"hosts": ELASTICSEARCH_DSL_HOST,

0 commit comments

Comments
 (0)