def retryable(options = {}, &block)
      options = {:max_retries => 4, :on_retry => nil, :retry_delay => 1.0}.merge!(options)
      retry_count = options[:max_retries]

      begin
        yield

      rescue Beaneater::NotConnected
        if retry_count > 0
          reconnect!
          retry_count -= 1
          sleep options[:retry_delay]
          options[:on_retry].call if options[:on_retry].respond_to?(:call)
          retry
        else # stop retrying
          raise e
        end
      end
    end
def retryable(options = {}, &block)
      options = {:max_retries => 4, :on_retry => nil, :retry_delay => 1.0}.merge!(options)
      retry_count = options[:max_retries]

      begin
        yield

      rescue Beaneater::NotConnected
        if retry_count > 0
          reconnect!
          retry_count -= 1
          sleep options[:retry_delay]
          options[:on_retry].call if options[:on_retry].respond_to?(:call)
          retry
        else # stop retrying
          raise e
        end
      end
    end
Yield to a block that will be retried several times if the connection to
 beanstalk goes down and is able to be re-established.

 @param options Hash Options. Valid options are:
   :max_retries       Integer The maximum number of times the block will be yielded to.
                              Defaults to 4
   :on_retry          Proc    An optional proc that will be called for each retry. Will be
                              called after the connection is re-established and :retry_delay
                              has passed but before the block is yielded to again
   :retry_delay       Float   The amount to sleep before retrying. Defaults to 1.0
 @raise Beaneater::NotConnected If a connection is unable to be re-established