class Goodguide::Health

Constants

VERSION

Attributes

booted_at[R]
deployed_at[W]
gg_env[W]
hostname[W]
revision[W]

Public Class Methods

app() click to toggle source
# File lib/goodguide/health.rb, line 14
def app
  health = instance
  Rack::Builder.app do
    use NewlineMiddleware

    map '/status' do
      run health.pinglish
    end
    map '/' do
      run health
    end
  end
end
new() click to toggle source
# File lib/goodguide/health.rb, line 41
def initialize
  @booted_at = Time.now.utc
end
reset() click to toggle source
# File lib/goodguide/health.rb, line 28
def reset
  @instance = nil
end

Private Class Methods

instance() click to toggle source
# File lib/goodguide/health.rb, line 36
def instance
  @instance ||= new
end

Public Instance Methods

call(env) click to toggle source
# File lib/goodguide/health.rb, line 76
def call(env)
  [200, { 'Content-Type' => 'text/plain' }, ["OK\n"]]
end
check(*args, &block) click to toggle source
# File lib/goodguide/health.rb, line 94
def check(*args, &block)
  pinglish.check(*args, &block)
end
configure(&block) click to toggle source
# File lib/goodguide/health.rb, line 80
def configure(&block)
  block.call(self)
end
deployed_at() click to toggle source
# File lib/goodguide/health.rb, line 66
def deployed_at
  @deployed_at ||= ENV.key?('DEPLOYMENT_TIMESTAMP') ?
    Time.at(ENV['DEPLOYMENT_TIMESTAMP'].to_i).utc :
    booted_at
end
gg_env() click to toggle source
# File lib/goodguide/health.rb, line 72
def gg_env
  @gg_env ||= ENV['GG_ENV']
end
hostname() click to toggle source
# File lib/goodguide/health.rb, line 48
def hostname
  @hostname ||= ENV.fetch('DEPLOYMENT_HOST') {
    ENV.fetch('HOSTNAME') {
      output = `hostname 2>/dev/null`
      $? == 0 ? output.chomp : nil
    }
  }
end
pinglish() click to toggle source
# File lib/goodguide/health.rb, line 84
def pinglish
  @pinglish ||= Pinglish.new do |ping|
    ping.check(:host) { hostname }
    ping.check(:deployed_at) { deployed_at.iso8601 }
    ping.check(:revision) { revision }
    ping.check(:started_at) { booted_at.iso8601 }
    ping.check(:gg_env) { gg_env }
  end
end
revision() click to toggle source
# File lib/goodguide/health.rb, line 57
def revision
  @revision ||= ENV.fetch('GIT_REVISION') {
    ENV.fetch('DEPLOYMENT_REVISION') {
      output = `git rev-parse HEAD 2>/dev/null`
      $? == 0 ? output.chomp : nil
    }
  }
end