Sha256: f7a4f7e24782f0477fe9c3c0f3b18d91c90ed2b710d2578d70548bac3f108882

Contents?: true

Size: 919 Bytes

Versions: 15

Compression:

Stored size: 919 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:)
      # rubocop:disable Rails/OutputSafety
      %(<!DOCTYPE html><html><body style="background-color: #{color}"></body></html>).html_safe
      # rubocop:enable Rails/OutputSafety
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
pg_rails-7.0.8.pre.alpha.107 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.106 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.105 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.104 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.103 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.102 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.101 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.100 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.99 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.98 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.97 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.96 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.95 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.94 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.0.8.pre.alpha.93 pg_engine/app/controllers/pg_engine/health_controller.rb