Skip to content

Commit 9745ec9

Browse files
committed
doc: Document the backoff class better.
1 parent 7a7cfe6 commit 9745ec9

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

zulip/zulip/__init__.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,27 @@
3333
API_VERSTRING = "v1/"
3434

3535
class CountingBackoff:
36-
def __init__(self, maximum_retries: int = 10, timeout_success_equivalent: Optional[float] = None, delay_cap: float = 90.0) -> None:
36+
def __init__(
37+
self,
38+
maximum_retries: int = 10,
39+
timeout_success_equivalent: Optional[float] = None,
40+
delay_cap: float = 90.0,
41+
) -> None:
42+
"""Sets up a retry-backoff object. Example usage:
43+
backoff = zulip.CountingBackoff()
44+
while backoff.keep_going():
45+
try:
46+
something()
47+
backoff.succeed()
48+
except Exception:
49+
backoff.fail()
50+
51+
timeout_success_equivalent is used in cases where 'success' is
52+
never possible to determine automatically; it sets the
53+
threshold in seconds before the next keep_going/fail, above
54+
which the last run is treated like it was a success.
55+
56+
"""
3757
self.number_of_retries = 0
3858
self.maximum_retries = maximum_retries
3959
self.timeout_success_equivalent = timeout_success_equivalent

0 commit comments

Comments
 (0)