Skip to content

Commit b174013

Browse files
committed
app: Convert health checks to use OKComputer
* The Alma patron fetch has been converted to a custom check. * ActionMailer is checked for connectivity. Note that this won't pass until emmahsax/okcomputer#21 is merged, because the `:test` delivery method isn't recognised for the ActionMailer check. Once it is merged, we can update the Gemfile to use the new version and then the tests will pass. Ref: AP-508
1 parent a5989da commit b174013

File tree

13 files changed

+62
-197
lines changed

13 files changed

+62
-197
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ gem 'lograge', '>=0.11.2'
2727
gem 'mutex_m'
2828
gem 'netaddr', '~> 1.5', '>= 1.5.1'
2929
gem 'net-ssh'
30+
gem 'okcomputer', '~> 1.19'
3031
gem 'omniauth', '~> 1.9', '>= 1.9.2'
3132
gem 'omniauth-cas', '~> 2.0'
3233
gem 'pg', '~> 1.2'

Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ GEM
7474
execjs (~> 2)
7575
awesome_print (1.9.2)
7676
base64 (0.3.0)
77+
benchmark (0.5.0)
7778
berkeley_library-alma (0.1.1)
7879
berkeley_library-logging (~> 0.2)
7980
berkeley_library-marc (~> 0.3.1)
@@ -258,6 +259,8 @@ GEM
258259
oj (3.16.11)
259260
bigdecimal (>= 3.0)
260261
ostruct (>= 0.2)
262+
okcomputer (1.19.1)
263+
benchmark
261264
omniauth (1.9.2)
262265
hashie (>= 3.4.6)
263266
rack (>= 1.6.2, < 3)
@@ -500,6 +503,7 @@ DEPENDENCIES
500503
mutex_m
501504
net-ssh
502505
netaddr (~> 1.5, >= 1.5.1)
506+
okcomputer (~> 1.19)
503507
omniauth (~> 1.9, >= 1.9.2)
504508
omniauth-cas (~> 2.0)
505509
pg (~> 1.2)

app/controllers/home_controller.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
# We'll likely be asked to remove this at some point, but for now it's useful
44
# to have in development.
55
class HomeController < ApplicationController
6-
7-
# TODO: Move this to a HealthController that extends ActionController::API
8-
# - note: may involve extracting some of ApplicationController into a mixin
9-
def health
10-
check = Health::Check.new
11-
render json: check, status: check.http_status_code
12-
end
13-
146
def admin
157
render :admin if require_framework_admin!
168
end

app/lib/health/check.rb

Lines changed: 0 additions & 57 deletions
This file was deleted.

app/lib/health/result.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/lib/health/status.rb

Lines changed: 0 additions & 23 deletions
This file was deleted.

config/initializers/okcomputer.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
# Health check configuration
4+
5+
OkComputer.logger = Rails.logger
6+
OkComputer.check_in_parallel = true
7+
8+
class AlmaPatronCheck < OkComputer::Check
9+
TEST_PATRON_ID = '012158720'
10+
11+
def check
12+
Alma::User.find(TEST_PATRON_ID)
13+
mark_message 'Success'
14+
rescue StandardError => e
15+
mark_failure
16+
mark_message "Failed: #{e}"
17+
end
18+
end
19+
20+
# Ensure Alma API is working.
21+
OkComputer::Registry.register 'alma-patron-lookup', AlmaPatronCheck.new
22+
23+
# Ensure database migrations have been run.
24+
OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new
25+
26+
# Ensure connectivity to the mail system.
27+
OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
root to: redirect('/forms/altmedia/new')
33

44
get 'admin', to: 'home#admin'
5-
get 'health', to: 'home#health'
5+
get 'health', to: 'ok_computer/ok_computer#index', defaults: { format: :json }
66
get 'home', to: 'home#index'
77
get 'build_info', to: 'home#build_info'
88

lib/tasks/health.rake

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/lib/health/status_spec.rb

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)