-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1781 from datadryad/3472-healthcheck-page
added health check endpoint
- Loading branch information
Showing
2 changed files
with
89 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class HealthController < ApplicationController | ||
|
||
def check | ||
health_status = { status: 'OK' } | ||
|
||
# Check database connectivity | ||
begin | ||
StashEngine::Identifier.last | ||
health_status[:database] = 'connected' | ||
rescue StandardError => e | ||
health_status[:database] = 'not connected' | ||
health_status[:database_error] = e.message if params[:advanced] | ||
end | ||
|
||
# Check Solr connectivity | ||
begin | ||
solr = RSolr.connect(url: Blacklight.connection_config[:url]) | ||
solr.get('select', params: { fl: 'dc_identifier_s', rows: 1 }) | ||
health_status[:solr] = 'connected' | ||
rescue StandardError => e | ||
health_status[:solr] = 'not connected' | ||
health_status[:solr_error] = e.message if params[:advanced] | ||
end | ||
|
||
# Check AWS S3 connectivity | ||
begin | ||
if Stash::Aws::S3.new.exists?(s3_key: 's3_status_check.txt') | ||
health_status[:aws_s3] = 'connected' | ||
else | ||
health_status[:aws_s3] = 'not connected' | ||
health_status[:aws_s3_error] = 'file does not exist' if params[:advanced] | ||
end | ||
rescue StandardError => e | ||
health_status[:aws_s3] = 'not connected' | ||
health_status[:aws_s3_error] = e.message if params[:advanced] | ||
end | ||
|
||
status_code = health_status.values.include?('not connected') ? :service_unavailable : :ok | ||
health_status[:status] = status_code | ||
render json: health_status, status: status_code | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters