Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .yarnrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# yarn lockfile v1


lastUpdateCheck 1762849565021
lastUpdateCheck 1770150293563
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.7.8 (xxxx-xx-xx)

* Implement OKComputer for healthchecks
* Refactor collector_spec to not include brittle ".ordered" expectations

# 1.7.5 (2025-12-17)

* Hotfix for release workflow issue
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gem 'jsbundling-rails'
gem 'jwt', '~> 2.2'
# Workaround for https://github.com/alexspeller/non-stupid-digest-assets/issues/54
gem 'non-stupid-digest-assets', git: 'https://github.com/BerkeleyLibrary/non-stupid-digest-assets.git', ref: '1de0c38'
gem 'okcomputer', '~> 1.19', '>= 1.19.1'
gem 'omniauth-cas', '~> 2.0'
gem 'pagy', '~> 5.6'
gem 'pg', '~> 1.2'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ GEM
amazing_print (1.4.0)
ast (2.4.2)
awesome_print (1.9.2)
benchmark (0.5.0)
berkeley_library-alma (0.0.7.1)
berkeley_library-logging (~> 0.2)
berkeley_library-marc (~> 0.3.1)
Expand Down Expand Up @@ -217,6 +218,8 @@ GEM
nokogiri (1.15.2-x86_64-linux)
racc (~> 1.4)
oj (3.14.3)
okcomputer (1.19.1)
benchmark
omniauth (1.9.2)
hashie (>= 3.4.6)
rack (>= 1.6.2, < 3)
Expand Down Expand Up @@ -411,6 +414,7 @@ DEPENDENCIES
jwt (~> 2.2)
listen
non-stupid-digest-assets!
okcomputer (~> 1.19, >= 1.19.1)
omniauth-cas (~> 2.0)
pagy (~> 5.6)
pg (~> 1.2)
Expand Down
19 changes: 0 additions & 19 deletions app/controllers/health_controller.rb

This file was deleted.

149 changes: 0 additions & 149 deletions app/lib/health/check.rb

This file was deleted.

30 changes: 0 additions & 30 deletions app/lib/health/result.rb

This file was deleted.

28 changes: 0 additions & 28 deletions app/lib/health/status.rb

This file was deleted.

13 changes: 13 additions & 0 deletions app/lib/health_checks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module HealthChecks
CHECK_FILES = %w[
iiif_server_check
lending_root_path
test_item_exists
].freeze

CHECK_FILES.each do |name|
require File.join(__dir__, "health_checks/#{name}")
end
end
52 changes: 52 additions & 0 deletions app/lib/health_checks/iiif_server_check.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module HealthChecks
class IIIFServerCheck < OkComputer::Check
include BerkeleyLibrary::Logging

def check
result = validate_iiif_server
mark_message result[:message]
mark_failure if result[:failure]
rescue StandardError => e
logger.error(e)
mark_message e.class.name
mark_failure
end

private

def iiif_connection
@iiif_connection ||= Faraday.new do |f|
f.options.open_timeout = 2
f.options.timeout = 3
end
end

def iiif_test_uri
base_uri = Lending::Config.iiif_base_uri
return unless base_uri

item = Item.active.first || Item.inactive.first
return unless item

BerkeleyLibrary::Util::URIs.append(
base_uri,
item.iiif_directory.first_image_url_path,
'info.json'
)
end

# Returns a hash with :message and :failure keys
def validate_iiif_server
test_uri = iiif_test_uri
return { message: 'Unable to construct test image URI', failure: true } unless test_uri

response = iiif_connection.head(test_uri)
return { message: "HEAD #{test_uri} returned status #{response.status}", failure: true } unless response.success?

acao_header = response.headers['Access-Control-Allow-Origin']
return { message: "HEAD #{test_uri} missing Access-Control-Allow-Origin header", failure: true } if acao_header.blank?

{ message: 'IIIF server reachable', failure: false }
end
end
end
31 changes: 31 additions & 0 deletions app/lib/health_checks/lending_root_path.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module HealthChecks
class LendingRootPath < OkComputer::Check
include BerkeleyLibrary::Logging

def check
result = validate_lending_root
mark_message result[:message]
mark_failure if result[:failure]
rescue StandardError => e
logger.error(e)
mark_message "Error: #{e.class.name}"
mark_failure
end

private

def lending_root
@lending_root ||= Lending::Config.lending_root_path
end

# Returns a hash with :message and :failure keys
def validate_lending_root
return { message: 'Lending root path not set', failure: true } unless lending_root
return { message: "Not a pathname: #{lending_root.inspect}", failure: true } unless lending_root.is_a?(Pathname)
return { message: "Not a directory: #{lending_root}", failure: true } unless lending_root.directory?
return { message: "Directory not readable: #{lending_root}", failure: true } unless lending_root.readable?

{ message: 'Lending root path exists and is readable', failure: false }
end
end
end
Loading