Skip to content

Commit

Permalink
Add missing doc for aspectlib.contrib.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Jun 10, 2015
1 parent 7e2c541 commit 18e4585
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
13 changes: 13 additions & 0 deletions docs/reference/aspectlib.contrib.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Reference: ``aspectlib.debug``
==============================

.. autosummary::
:nosignatures:

aspectlib.contrib.retry
aspectlib.contrib.retry.exponential_backoff
aspectlib.contrib.retry.straight_backoff
aspectlib.contrib.retry.flat_backoff

.. automodule:: aspectlib.contrib
:members:
23 changes: 20 additions & 3 deletions src/aspectlib/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ def Retry(cutpoint, *args, **kwargs):
sleep(timeout)
return Retry if func is None else Retry(func)

retry.exponential_backoff = lambda count: 2 ** count
retry.straight_backoff = lambda count: (1, 2, 5)[count] if count < 3 else 5 * count - 5
retry.flat_backoff = lambda count: (1, 2, 5, 10, 15, 30, 60)[count if count < 6 else -1]
def exponential_backoff(count):
"""
Wait 2**N seconds.
"""
return 2 ** count
retry.exponential_backoff = exponential_backoff

def straight_backoff(count):
"""
Wait 1, 2, 5 seconds. All retries after the 3rd retry will wait 5*N-5 seconds.
"""
return (1, 2, 5)[count] if count < 3 else 5 * count - 5
retry.straight_backoff = straight_backoff

def flat_backoff(count):
"""
Wait 1, 2, 5, 10, 15, 30 and 60 seconds. All retries after the 5th retry will wait 60 seconds.
"""
return (1, 2, 5, 10, 15, 30, 60)[count if count < 6 else -1]
retry.flat_backoff = flat_backoff

0 comments on commit 18e4585

Please sign in to comment.