From eb2a5c6e19b159674874be7aa5e97b2cab4d1d2e Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 14 Feb 2021 16:41:19 +0100 Subject: [PATCH] Healthcheck added https://github.com/linqueta/rails-healthcheck --- CHECKS | 1 + Gemfile | 1 + Gemfile.lock | 3 +++ config/initializers/healthcheck.rb | 21 +++++++++++++++++++++ config/routes.rb | 1 + 5 files changed, 27 insertions(+) create mode 100644 CHECKS create mode 100644 config/initializers/healthcheck.rb diff --git a/CHECKS b/CHECKS new file mode 100644 index 0000000..0923d94 --- /dev/null +++ b/CHECKS @@ -0,0 +1 @@ +/healthcheck diff --git a/Gemfile b/Gemfile index 204134a..dff0a20 100644 --- a/Gemfile +++ b/Gemfile @@ -40,6 +40,7 @@ gem 'jbuilder', '~> 2.5' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'rails-healthcheck' group :development do # Access an IRB console on exception pages or by using <%= console %> anywhere in the code. diff --git a/Gemfile.lock b/Gemfile.lock index 8f34799..cd49b43 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -285,6 +285,8 @@ GEM activesupport (>= 4.2) choice (~> 0.2.0) ruby-graphviz (~> 1.2) + rails-healthcheck (1.2.0) + rails rails-html-sanitizer (1.3.0) loofah (~> 2.3) railties (6.1.2.1) @@ -447,6 +449,7 @@ DEPENDENCIES puma (~> 3.0) rails (~> 6.0) rails-erd + rails-healthcheck sass-rails (~> 5.0) sdoc (~> 0.4.0) selenium-webdriver diff --git a/config/initializers/healthcheck.rb b/config/initializers/healthcheck.rb new file mode 100644 index 0000000..0fea1a2 --- /dev/null +++ b/config/initializers/healthcheck.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +Healthcheck.configure do |config| + config.success = 200 + config.error = 503 + config.verbose = false + config.route = '/healthcheck' + config.method = :get + + # -- Custom Response -- + # config.custom = lambda { |controller, checker| + # controller.render json: my_custom_response unless checker.errored? + # ... + # } + + # -- Checks -- + # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') } + # config.add_check :migrations, -> { ActiveRecord::Migration.check_pending! } + # config.add_check :cache, -> { Rails.cache.read('some_key') } + # config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') } +end diff --git a/config/routes.rb b/config/routes.rb index afc494a..061ba04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,6 @@ Rails.application.routes.draw do + Healthcheck.routes(self) get 'admin/status' get 'admin/screenshots'