class KOAUtils::HealthCheck
Public Class Methods
call(env)
click to toggle source
# File lib/koa-utils/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_check()
click to toggle source
# File lib/koa-utils/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