Skip to content

Commit

Permalink
🔧 Ajoute un HealthCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
cprodhomme authored and etienneCharignon committed Feb 5, 2025
1 parent 174d490 commit 2805a60
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ gem 'geocoder'
gem 'google-api-client', '~> 0.53'
gem 'google_drive', '~> 3.0'
gem 'groupdate'
gem 'health_check'
gem 'i18n-js', '~> 3.9.0'
gem 'image_processing'
gem 'inline_svg'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ GEM
activesupport (>= 5.2)
hashdiff (1.1.2)
hashery (2.1.2)
health_check (3.1.0)
railties (>= 5.0)
html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4)
http-accept (1.7.0)
Expand Down Expand Up @@ -736,6 +738,7 @@ DEPENDENCIES
groupdate
guard-rspec
guard-rubocop
health_check
i18n-js (~> 3.9.0)
image_processing
inline_svg
Expand Down
38 changes: 38 additions & 0 deletions config/initializers/health_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

HealthCheck.setup do |config|
# on souhaite avoir l'url /healthcheck/all.json
config.uri = '/pro/healthcheck'

# Permet de voir l'erreur en activant la variable d'environnement
# HEALTHCHECK_DEBUG=true
config.include_error_in_response_body = ENV.fetch('HEALTHCHECK_DEBUG', false)

config.log_level = 'info'

# on souhaite retourner une 503 plutôt qu'une 500
config.http_status_for_error_text = 503
config.http_status_for_error_object = 503

# configurer comme vous le souhaitez
# les check standard sont pour /healthcheck.json
config.standard_checks = %w[database migrations]
# les check complets sont pour /healthcheck/all.json
config.full_checks = %w[site database migrations redis sidekiq-redis]

# Envoyer le détail de l'erreur sur Slack
config.on_failure do |checks, msg|
url = ENV.fetch('URL_WEBHOOK_HEALTH_CHECK', nil)
if url.present?
message = "[#{checks}] #{msg}"
payload = {
text: message
}

require 'net/http'
require 'uri'

Net::HTTP.post URI(url), payload.to_json, 'Content-Type': 'application/json'
end
end
end

0 comments on commit 2805a60

Please sign in to comment.