Skip to content

Prevent error message in case of giveup using #217

Open
@lesnik512

Description

@lesnik512

Hello, thank you for a grate tool!

Is it possible to not write error messages in case of giving up due to using giveup attribute?

Case is similar to this #108, when I need to check for some fields of exceptions to decide:

def _connection_retry_backoff_handler(exception: Exception) -> bool:
    if (
        isinstance(exception, DBAPIError)
        and hasattr(exception, "orig")
        and isinstance(exception.orig.__cause__, asyncpg.PostgresConnectionError)  # type: ignore[union-attr]
    ):
        logger.debug("postgres_reconnect, backoff triggered")
        return False

    logger.debug("postgres_reconnect, giving up on backoff")
    return True


def postgres_reconnect(func: typing.Callable[P, typing.Awaitable[T]]) -> typing.Callable[P, typing.Awaitable[T]]:
    @backoff.on_exception(
        backoff.expo,
        (DBAPIError,),
        max_tries=settings.DB_UTILS_CONNECTION_TRIES,
        giveup=_connection_retry_backoff_handler,
    )
    @functools.wraps(func)
    async def wrapped_method(*args: P.args, **kwargs: P.kwargs) -> T:
        return await func(*args, **kwargs)

    return wrapped_method

Because now I receive this

Giving up create_user(...) after 1 tries

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions