Skip to content

Commit 7d1588a

Browse files
refactor: Simplify retry logic in bundle analysis and upload finisher tasks
1 parent 9ca255c commit 7d1588a

File tree

3 files changed

+20
-29
lines changed

3 files changed

+20
-29
lines changed

apps/worker/services/lock_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def locked(
128128
)
129129
countdown = min(countdown_unbounded, max_retry_cap)
130130

131+
# None means no max retries (infinite retries)
131132
max_attempts = max_retries + 1 if max_retries is not None else None
132133
if max_attempts is not None and retry_num >= max_attempts:
133134
error_msg = (

apps/worker/tasks/bundle_analysis_processor.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,32 @@ def process_impl_within_lock(
207207
result: ProcessingResult = report_service.process_upload(
208208
commit, upload, compare_sha
209209
)
210-
if (
211-
result.error
212-
and result.error.is_retryable
213-
and self.request.retries < self.max_retries
214-
):
210+
if result.error and result.error.is_retryable:
211+
if self._has_exceeded_max_attempts(self.max_retries):
212+
attempts = self.attempts
213+
max_attempts = self.max_retries + 1
214+
log.error(
215+
"Bundle analysis processor exceeded max retries",
216+
extra={
217+
"attempts": attempts,
218+
"commitid": commitid,
219+
"max_attempts": max_attempts,
220+
"max_retries": self.max_retries,
221+
"repoid": repoid,
222+
},
223+
)
224+
return
215225
log.warn(
216226
"Attempting to retry bundle analysis upload",
217227
extra={
228+
"commitid": commitid,
218229
"repoid": repoid,
219-
"commit": commitid,
220230
"commit_yaml": commit_yaml,
221231
"params": params,
222232
"result": result.as_dict(),
223233
},
224234
)
225-
self.retry(countdown=30 * (2**self.request.retries))
235+
self.retry(max_retries=self.max_retries, countdown=30 * (2**self.request.retries))
226236
result.update_upload(carriedforward=carriedforward)
227237
db_session.commit()
228238

apps/worker/tasks/upload_finisher.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,7 @@ def _process_reports_with_lock(
493493
upload_ids=upload_ids,
494494
error=Errors.INTERNAL_RETRYING,
495495
)
496-
if not self.safe_retry(max_retries=MAX_RETRIES, countdown=retry.countdown):
497-
attempts = self.attempts
498-
log.error(
499-
"Failed to schedule retry for upload finisher",
500-
extra={
501-
"attempts": attempts,
502-
"commitid": commitid,
503-
"repoid": repoid,
504-
},
505-
)
506-
return
496+
self.retry(max_retries=MAX_RETRIES, countdown=retry.countdown)
507497

508498
def _handle_finisher_lock(
509499
self,
@@ -621,17 +611,7 @@ def _handle_finisher_lock(
621611
upload_ids=upload_ids,
622612
error=Errors.INTERNAL_RETRYING,
623613
)
624-
if not self.safe_retry(max_retries=MAX_RETRIES, countdown=retry.countdown):
625-
attempts = self.attempts
626-
log.error(
627-
"Failed to schedule retry for upload finisher (finisher lock)",
628-
extra={
629-
"attempts": attempts,
630-
"commitid": commitid,
631-
"repoid": repoid,
632-
},
633-
)
634-
return
614+
self.retry(max_retries=MAX_RETRIES, countdown=retry.countdown)
635615

636616
def finish_reports_processing(
637617
self,

0 commit comments

Comments
 (0)