Skip to content

Commit 5aa1050

Browse files
committed
API: Added random exponential backoff to do_api_query
1 parent 32a46cb commit 5aa1050

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

zulip/zulip/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import random
3636
import types
3737
from distutils.version import LooseVersion
38-
38+
import random
3939
import distro
4040
from six.moves.configparser import SafeConfigParser
4141
from six.moves import urllib
@@ -525,7 +525,10 @@ 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)
528+
delay_cap = 10
529+
delay_base = 0.5
530+
delay_time = random.random() * min(delay_cap, delay_base * (2 ** query_state["failures"]))
531+
time.sleep(delay_time)
529532
query_state["failures"] += 1
530533
return True
531534

0 commit comments

Comments
 (0)