Title here
Summary here
Create a controller for health check in app/controllers/health_controller.rb:
class HealthController < ApplicationController
def index
database_status = Health.database ? 'OK' : 'FAILED'
redis_status = Health.redis ? 'OK' : 'FAILED'
render json: { database: database_status, redis: redis_status }
end
end
Create a class for health check:
class Health
def self.database
ActiveRecord::Base.connection.active?
end
def self.redis
Redis.new.ping == "PONG"
rescue StandardError
false
end
end
Define a route in config/routes.rb:
get '/heartbeat', to: 'health#index'
Visit http://localhost:3000/heartbeat
in your browser or send a GET request to that endpoint to see the health check results.