module Idlc::Deploy::Power

def wait_for_response(endpoint, success_text = nil, wait_timeout = 1500, sleep_time = 10)

def wait_for_response(endpoint, success_text = nil, wait_timeout = 1500, sleep_time = 10)
  connected = false
  start_time = Time.now
  until connected
    begin
      if success_text.nil? || success_text == ''
        response = http_request("#{endpoint}/diagnostics/ping")
        connected = success(response.body)
      else
        response = http_request(endpoint)
        connected = simple_success(response.body, success_text)
      end
    rescue ConnectionError, Net::OpenTimeout, JSON::ParserError, Errno::ECONNREFUSED
      check_timeout(start_time, wait_timeout)
      sleep sleep_time
    end
  end
  msg "recieved response from #{endpoint} !"
  true
end