Class: MysqlHealth::Server

Inherits:
EM::Connection
  • Object
show all
Includes:
EM::HttpServer
Defined in:
lib/mysql_health/server.rb

Instance Method Summary collapse

Instance Method Details

#http_response(data) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/mysql_health/server.rb', line 35

def http_response(data)
   MysqlHealth.log.debug("http_response")
  response = EventMachine::DelegatedHttpResponse.new(self)
  if data.nil?
    response.status = '500 Server Error'
    response.content = "Empty call to http_response\n"
  else
    data.each_pair do |k,v|
      MysqlHealth.log.debug("#{k}=#{v}")
      if k == :content_type
        response.send(k, v)
      else
        response.send("#{k}=".to_sym, v)
      end
    end
  end
  response
end

#post_initObject



30
31
32
33
# File 'lib/mysql_health/server.rb', line 30

def post_init
  super
  no_environment_strings
end

#process_http_requestObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mysql_health/server.rb', line 54

def process_http_request
  response = nil
  begin
    case @http_path_info
    when '/master_status'
      response = http_response(MysqlHealth.health.master_status)
    when '/slave_status'
      response = http_response(MysqlHealth.health.slave_status)
    else
      response = http_response({:status => '501 Not Implemented'})
    end
  rescue Exception => e
    response = http_response({:status => '500 Server Error', :content => e.message + "\n" + e.backtrace.join("\n")})
  end
  response.send_response
end