(fn, *, args=tuple(), retry_delay: int, action: str)
Decorator to repeatedly call fn in case of Redis connection problems
Decorator to repeatedly call fn in case of Redis connection problems
Decorator to repeatedly call fn in case of Redis connection problems
async def retry_on_redis_connection_failure(fn, *, args=tuple(), retry_delay: int, action: str):
    """Decorator to repeatedly call fn in case of Redis connection problems"""
    while True:
        try:
            return await fn(*args)
        except (ConnectionClosedError, ConnectionResetError):
            # ConnectionClosedError is from aioredis. However, sometimes the connection
            # can die outside of aioredis, in which case we get a builtin ConnectionResetError.
            logger.warning(
                f"Redis connection lost while {action}, reconnecting "
                f"in {retry_delay} seconds..."
            )
            await asyncio.sleep(retry_delay)
        except ConnectionRefusedError:
            logger.warning(
                f"Redis connection refused while {action}, retrying " f"in {retry_delay} seconds..."
            )
            await asyncio.sleep(retry_delay)
        except ReplyError as e:
            if "LOADING" in str(e):
                logger.warning(
                    f"Redis server is still loading, retrying " f"in {retry_delay} seconds..."
                )
                await asyncio.sleep(retry_delay)
            else:
                raise
async def retry_on_redis_connection_failure ( fn , * , args = tuple ( ) , retry_delay : int , action : str ) : while True : try : return await fn ( * args ) except ( ConnectionClosedError , ConnectionResetError ) : # ConnectionClosedError is from aioredis. However, sometimes the connection # can die outside of aioredis, in which case we get a builtin ConnectionResetError. logger . warning ( f"Redis connection lost while {action}, reconnecting " f"in {retry_delay} seconds..." ) await asyncio . sleep ( retry_delay ) except ConnectionRefusedError : logger . warning ( f"Redis connection refused while {action}, retrying " f"in {retry_delay} seconds..." ) await asyncio . sleep ( retry_delay ) except ReplyError as e : if "LOADING" in str ( e ) : logger . warning ( f"Redis server is still loading, retrying " f"in {retry_delay} seconds..." ) await asyncio . sleep ( retry_delay ) else : raise