Class: Koa::HealthCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/koa/health-check.rb

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/koa/health-check.rb', line 5

def self.call(env)
  begin
    Timeout::timeout(2) do
      db_check
    end
  rescue => e
    return [500, {"Content-Type" => "text/json"},
      [JSON.dump({error: e.message})]]
  end
  [200, {"Content-Type" => "text/json"}, [JSON.dump({info: Time.now})]]
end

.db_checkObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/koa/health-check.rb', line 17

def self.db_check
  query = "select * from information_schema.tables"
  if defined?(ActiveRecord)
    ActiveRecord::Base.connection.execute(query)
  elsif defined?(Sequel)
    c = Sequel.connect(ENV["DATABASE_URL"])
    c.exec(query)
    c.disconnect
  end
end