docbrown/app/controllers/api/v0/health_checks_controller.rb
Fernando Valverde cf3bde4259
Add mobile push notifications to Forem (#12419)
* First commit with iOS PN working

* RPush cleanup worker + unique jobs config

* Remove rpush tables from schema.rb

* PR feedback

* Feature flag and test for route

* Tests and feature flag PushNotification ::Send

* Update app/controllers/devices_controller.rb

Co-authored-by: Michael Kohl <citizen428@dev.to>

* Update spec/routing/devices_routes_spec.rb

Co-authored-by: Michael Kohl <citizen428@dev.to>

* Update spec/services/push_notifications/send_spec.rb

Co-authored-by: Michael Kohl <citizen428@dev.to>

* PR feedback

* Set Rpush driver and url

* More PR feedback

* Apply suggestions from code review

Co-authored-by: Jamie Gaskins <jgaskins@gmail.com>

* PR feedback from Rhymes

* Don’t double render

* Sure

Co-authored-by: Josh Puetz <hi@joshpuetz.com>
Co-authored-by: Josh Puetz <josh@dev.to>
Co-authored-by: Michael Kohl <citizen428@dev.to>
Co-authored-by: Jamie Gaskins <jgaskins@gmail.com>
2021-03-12 14:08:18 -06:00

58 lines
1.5 KiB
Ruby

module Api
module V0
class HealthChecksController < ApiController
before_action :authenticate_with_token
def app
render json: { message: "App is up!" }, status: :ok
end
def search
if Search::Client.ping
render json: { message: "Search ping succeeded!" }, status: :ok
else
render json: { message: "Search ping failed!" }, status: :internal_server_error
end
end
def database
if ActiveRecord::Base.connected?
render json: { message: "Database connected" }, status: :ok
else
render json: { message: "Database NOT connected!" }, status: :internal_server_error
end
end
def cache
if all_cache_instances_connected?
render json: { message: "Redis connected" }, status: :ok
else
render json: { message: "Redis NOT connected!" }, status: :internal_server_error
end
end
private
def authenticate_with_token
return if request.local?
key = request.headers["health-check-token"]
return if key == SiteConfig.health_check_token
error_unauthorized
end
def all_cache_instances_connected?
[
ENV["REDIS_URL"],
ENV["REDIS_SESSIONS_URL"],
ENV["REDIS_SIDEKIQ_URL"],
ENV["REDIS_RPUSH_URL"],
].compact.all? do |url|
Redis.new(url: url).ping == "PONG"
end
end
end
end
end