Class: KOAUtils::HealthCheck
- Inherits:
-
Object
- Object
- KOAUtils::HealthCheck
- Defined in:
- lib/koa-utils/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-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.})]] end [200, {"Content-Type" => "text/json"}, [JSON.dump({info: Time.now})]] end |
.db_check ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# 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 |