Sha256: bd960c1ec821c6a30afd0fc503457460d919fe31edd44e8cc90a65d6f7be3f8d

Contents?: true

Size: 834 Bytes

Versions: 6

Compression:

Stored size: 834 Bytes

Contents

module PgEngine
  class HealthController < ApplicationController
    rescue_from(Exception) do |error|
      pg_err error
      render_down
    end

    def show
      check_redis
      check_postgres
      render_up
    end

    private

    def check_postgres
      return if User.count.is_a? Integer

      raise PgEngine::Error, 'postgres is down'
    end

    def check_redis
      return if Kredis.counter('healthcheck').increment.is_a? Integer

      raise PgEngine::Error, 'redis is down'
    end

    def render_up
      render html: html_status(color: '#005500')
    end

    def render_down
      render html: html_status(color: '#990000'), status: :internal_server_error
    end

    def html_status(color:)
      %(<!DOCTYPE html><html><body style="background-color: #{color}"></body></html>).html_safe
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pg_rails-7.6.1 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.6.0 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.5.7 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.5.6 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.5.5 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.5.4 pg_engine/app/controllers/pg_engine/health_controller.rb