Skip to content

Commit

Permalink
Basic impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Šarūnas Navickas committed Jun 4, 2016
1 parent 4891f80 commit d60fb3e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions robust/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ class ContinuousFailureException(Exception):

class TimeoutException(Exception):
pass


class ConnectionCutException(Exception):
pass
4 changes: 3 additions & 1 deletion robust/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pytest import raises
from robust.tools import retry, timeout, breaker
from robust.exception import ContinuousFailureException, TimeoutException
from robust.exception import (ContinuousFailureException,
TimeoutException,
ConnectionCutException)


class TestRetryCase(object):
Expand Down
19 changes: 19 additions & 0 deletions robust/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ def breaker(limit, revive, on_fail=None):
After :revive: seconds it allows one connection to pass.
If it succeeds - counter is reset, if doesn't - we wait another :revive: seconds
"""

def injector(fn):
counter = 0

@wraps(fn)
def wrapper(*args, **kwargs):
nonlocal counter
if counter > limit:
pass

try:
return fn(*args, **kwargs)
except Exception:
counter += 1
raise

return wrapper

return injector

0 comments on commit d60fb3e

Please sign in to comment.