Class: Emque::Consuming::CommandReceivers::HttpServer::Handler

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/emque/consuming/command_receivers/http_server.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/emque/consuming/command_receivers/http_server.rb', line 42

def call(env)
  req = env["REQUEST_URI"].split("/")

  case req[1]
  when "status"
    return render_status
  when "control"
    case req[2]
    when "errors"
      if req[3..-1] && runner.control.errors(*req[3..-1]) == true
        return render_status
      end
    else
      if req[2].is_a?(String) &&
         app.manager.workers.has_key?(req[2].to_sym) &&
         runner.control.workers(*req[2..-1]) == true
        return render_status
      end
    end
  end

  render_404
end

#render_404Object



66
67
68
# File 'lib/emque/consuming/command_receivers/http_server.rb', line 66

def render_404
  [404, {}, ["Not Found"]]
end

#render_status(additional = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/emque/consuming/command_receivers/http_server.rb', line 70

def render_status(additional = {})
  [
    200,
    {},
    [
      Oj.dump(
        runner.status.to_hsh.merge(additional),
        :mode => :compat
      )
    ]
  ]
end