Sha256: 23a249508c2f618953abcdc41f0669d25884e2dc767b70623fbcf89d6619bdbd

Contents?: true

Size: 876 Bytes

Versions: 45

Compression:

Stored size: 876 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
      # rubocop:enable Rails/OutputSafety
    end
  end
end

Version data entries

45 entries across 45 versions & 1 rubygems

Version Path
pg_rails-7.1.14 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.13 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.12 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.11 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.10 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.9 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.8 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.7 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.6 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.5 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.4 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.3 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.2 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.1.pre.6 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.1.pre.5 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.1.pre.4 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.1.pre.3 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.1.pre.2 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.1.pre.1 pg_engine/app/controllers/pg_engine/health_controller.rb
pg_rails-7.1.0 pg_engine/app/controllers/pg_engine/health_controller.rb