-
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 branch 'main' of github.com:datadryad/dryad-app into 3480-upgra…
…de-blacklight-and-solr-to-current-versions
- Loading branch information
Showing
40 changed files
with
328 additions
and
172 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
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
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 |
---|---|---|
@@ -1,42 +1,69 @@ | ||
class HealthController < ApplicationController | ||
|
||
def check | ||
health_status = { status: 'OK' } | ||
@health_status = {} | ||
populate_statuses | ||
|
||
status_code = @health_status.map { |_k, v| v[:status] }.include?('not connected') ? :service_unavailable : :ok | ||
notify_health_status_change(status_code, @health_status) | ||
|
||
render json: { status: status_code }.merge(@health_status), status: status_code and return if params.key?(:advanced) | ||
|
||
render json: { status: status_code }.merge(simple_response_hash), status: status_code | ||
end | ||
|
||
private | ||
|
||
def simple_response_hash | ||
return @simple_response_hash if @simple_response_hash | ||
|
||
@simple_response_hash = @health_status.each_with_object({}) do |(key, value), result| | ||
result[key] = value[:status] | ||
end | ||
end | ||
|
||
def populate_statuses | ||
# Check database connectivity | ||
@health_status[:database] = {} | ||
begin | ||
StashEngine::Identifier.last | ||
health_status[:database] = 'connected' | ||
@health_status[:database][:status] = 'connected' | ||
rescue StandardError => e | ||
health_status[:database] = 'not connected' | ||
health_status[:database_error] = e.message if params[:advanced] | ||
@health_status[:database][:status] = 'not connected' | ||
@health_status[:database][:error] = e.message | ||
end | ||
|
||
# Check Solr connectivity | ||
@health_status[:solr] = {} | ||
begin | ||
solr = RSolr.connect(url: Blacklight.connection_config[:url]) | ||
solr.get('select', params: { fl: 'dc_identifier_s', rows: 1 }) | ||
health_status[:solr] = 'connected' | ||
@health_status[:solr][:status] = 'connected' | ||
rescue StandardError => e | ||
health_status[:solr] = 'not connected' | ||
health_status[:solr_error] = e.message if params[:advanced] | ||
@health_status[:solr][:status] = 'not connected' | ||
@health_status[:solr][:error] = e.message | ||
end | ||
|
||
# Check AWS S3 connectivity | ||
@health_status[:aws_s3] = {} | ||
begin | ||
if Stash::Aws::S3.new.exists?(s3_key: 's3_status_check.txt') | ||
health_status[:aws_s3] = 'connected' | ||
@health_status[:aws_s3][:status] = 'connected' | ||
else | ||
health_status[:aws_s3] = 'not connected' | ||
health_status[:aws_s3_error] = 'file does not exist' if params[:advanced] | ||
@health_status[:aws_s3][:status] = 'not connected' | ||
@health_status[:aws_s3][:error] = 'file does not exist' | ||
end | ||
rescue StandardError => e | ||
health_status[:aws_s3] = 'not connected' | ||
health_status[:aws_s3_error] = e.message if params[:advanced] | ||
@health_status[:aws_s3][:status] = 'not connected' | ||
@health_status[:aws_s3][:error] = e.message | ||
end | ||
end | ||
|
||
def notify_health_status_change(status_code, health_status) | ||
old_statuses = Rails.cache.read('health_status') | ||
Rails.cache.write('health_status', simple_response_hash, expires_in: 10.minute) | ||
return if old_statuses == simple_response_hash | ||
|
||
status_code = health_status.values.include?('not connected') ? :service_unavailable : :ok | ||
health_status[:status] = status_code | ||
render json: health_status, status: status_code | ||
StashEngine::NotificationsMailer.health_status_change(status_code, health_status).deliver_now | ||
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
module StashEngine | ||
|
||
# Mails users about submissions | ||
class NotificationsMailer < ApplicationMailer | ||
|
||
def health_status_change(status_code, health_status) | ||
@status_code = status_code | ||
@health_status = health_status | ||
|
||
mail(to: 'devs@datadryad.org', subject: "#{rails_env}Health check status changed - #{status_code}") | ||
end | ||
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
Oops, something went wrong.