Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retry_exceptions lambda #64

Open
p-frolov opened this issue Oct 23, 2019 · 0 comments
Open

retry_exceptions lambda #64

p-frolov opened this issue Oct 23, 2019 · 0 comments

Comments

@p-frolov
Copy link

Hello,

I need additional checks before retry code, for instance:

def is_sql_exception_for_retry(exc: t_sql_errors):
    # sqlalchemy.exc.OperationalError
    # (psycopg2.OperationalError) server closed the connection unexpectedly
    # (psycopg2.OperationalError) could not connect to server: Connection refused
    message = exc._message()
    if "server closed the connection unexpectedly" in message:
        return True
    if "could not connect to server: Connection refused" in message:
        return True
    return False

In my case I can do only:

@redo.retriable(retry_exceptions=(sqlalchemy.exc.OperationalError, psycopg2.OperationalError), sleeptime=10, jitter=3)
def function():
    pass

I will be great to add to functional callback for retry.

Also I can define specific retry exception, check my function is_sql_exception_for_retry in retriable function and raise created exception, like this:

class MyRetryException(Exception):
    pass

@redo.retriable(retry_exceptions=(MyRetryException,), sleeptime=10, jitter=3)
def function():
    try:
      ...
    except  (sqlalchemy.exc.OperationalError, psycopg2.OperationalError) as exc:
        if is_sql_exception_for_retry(exc):
            raise MyRetryException()
        raise exc

but in this case I will lose convenience of decorator, and will have additional code in each retriable function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant