Skip to content

Commit 62f6f7c

Browse files
committed
api: Use Random Exponential Backoff in do_api_query method.
Fixes #537.
1 parent 9c3a3c2 commit 62f6f7c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

zulip/zulip/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,13 @@ def do_api_query(self, orig_request, url, method="POST",
509509
query_state = {
510510
'had_error_retry': False,
511511
'request': request,
512-
'failures': 0,
513512
} # type: Dict[str, Any]
514513

514+
# create Random Exponential Backoff object to perform retries using the method
515+
backoff = RandomExponentialBackoff(timeout_success_equivalent=300)
516+
515517
def error_retry(error_string):
516518
# type: (str) -> bool
517-
if not self.retry_on_errors or query_state["failures"] >= 10:
518-
return False
519519
if self.verbose:
520520
if not query_state["had_error_retry"]:
521521
sys.stdout.write("zulip API(%s): connection error%s -- retrying." %
@@ -525,9 +525,8 @@ def error_retry(error_string):
525525
sys.stdout.write(".")
526526
sys.stdout.flush()
527527
query_state["request"]["dont_block"] = json.dumps(True)
528-
time.sleep(1)
529-
query_state["failures"] += 1
530-
return True
528+
backoff.fail()
529+
return backoff.keep_going()
531530

532531
def end_error_retry(succeeded):
533532
# type: (bool) -> None

0 commit comments

Comments
 (0)