Skip to content

Commit

Permalink
A bit of styling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Jun 10, 2015
1 parent 18e4585 commit 1450658
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/aspectlib/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def retry(func=None, retries=5, backoff=None, exceptions=(IOError, OSError, EOFE
OSError: Tough luck!
"""

@Aspect(bind=True)
def Retry(cutpoint, *args, **kwargs):
def retry_aspect(cutpoint, *args, **kwargs):
for count in range(retries + 1):
try:
if count and cleanup:
Expand All @@ -55,7 +56,9 @@ def Retry(cutpoint, *args, **kwargs):
logger.exception("%s(%s, %s) raised exception %s. %s retries left. Sleeping %s secs.",
cutpoint.__name__, args, kwargs, exc, retries - count, timeout)
sleep(timeout)
return Retry if func is None else Retry(func)

return retry_aspect if func is None else retry_aspect(func)


def exponential_backoff(count):
"""
Expand All @@ -64,13 +67,15 @@ def exponential_backoff(count):
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.
Expand Down

0 comments on commit 1450658

Please sign in to comment.