'Ensure we have a connection to the server.
If not retry establishing the connection with the settings
specified.
Arguments:
errback (Callable): Optional callback called each time the
connection can\'t be established.  Arguments provided are
the exception raised and the interval that will be
slept ``(exc, interval)``.
max_retries (int): Maximum number of times to retry.
If this limit is exceeded the connection error
will be re-raised.
interval_start (float): The number of seconds we start
sleeping for.
interval_step (float): How many seconds added to the interval
for each retry.
interval_max (float): Maximum number of seconds to sleep between
each retry.
callback (Callable): Optional callback that is called for every
internal iteration (1 s).'

def ensure_connection(self, errback=None, max_retries=None, interval_start=2, interval_step=2, interval_max=30, callback=None, reraise_as_library_errors=True):

    def on_error(exc, intervals, retries, interval=0):
        round = self.completes_cycle(retries)
        if round:
            interval = next(intervals)
        if errback:
            errback(exc, interval)
        self.maybe_switch_next()
        return (interval if round else 0)
    ctx = self._reraise_as_library_errors
    if (not reraise_as_library_errors):
        ctx = self._dummy_context
    with ctx():
        retry_over_time(self.connect, self.recoverable_connection_errors, (), {}, on_error, max_retries, interval_start, interval_step, interval_max, callback)
    return self
