Skip to content

Commit 7377c3b

Browse files
authored
mercurial: refactor how we handle retries. (#102)
1 parent 577d643 commit 7377c3b

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

libmozevent/mercurial.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,21 @@ def get_status():
396396
)
397397
await asyncio.sleep(TRY_STATUS_DELAY)
398398

399+
def is_eligible_for_retry(self, error):
400+
"""
401+
Given a Mercurial error message, if it's an error likely due to a
402+
temporary connection problem, consider it as eligible for retry.
403+
"""
404+
eligible_errors = [
405+
"push failed on remote",
406+
"stream ended unexpectedly",
407+
"error: EOF occurred in violation of protocol",
408+
]
409+
for eligible_message in eligible_errors:
410+
if eligible_message in error:
411+
return True
412+
return False
413+
399414
async def handle_build(self, repository, build):
400415
"""
401416
Try to load and apply a diff on local clone
@@ -456,21 +471,7 @@ async def handle_build(self, repository, build):
456471
if isinstance(error_log, bytes):
457472
error_log = error_log.decode("utf-8")
458473

459-
def is_eligible_for_retry(error):
460-
"""
461-
Given a Mercurial error message, if it's an error likely due to a temporary connection problem, consider it as eligible for retry.
462-
"""
463-
eligible_errors = [
464-
"push failed on remote",
465-
"stream ended unexpectedly",
466-
"error: EOF occurred in violation of protocol",
467-
]
468-
for eligible_message in eligible_errors:
469-
if eligible_message in error_log:
470-
return True
471-
return False
472-
473-
if is_eligible_for_retry(error_log.lower()):
474+
if self.is_eligible_for_retry(error_log.lower()):
474475
build.retries += 1
475476
# Ensure try is opened
476477
await self.wait_try_available()

0 commit comments

Comments
 (0)