diff --git a/asxpio.rb b/asxpio.rb index df0935f..91ebef4 100644 --- a/asxpio.rb +++ b/asxpio.rb @@ -143,6 +143,18 @@ class AsxpioWeb < Sinatra::Base redirect '/thanks' end + # Liveness for the Docker HEALTHCHECK and the deploy pipeline. Pings the DB + # when invoicing is configured — a wedged connection pool should read as + # unhealthy, not just "process exists". + get '/healthz' do + begin + DB.connection['SELECT 1'].get if defined?(Invoice) + rescue Sequel::Error + halt 503, 'db unreachable' + end + 'ok' + end + get '/thanks' do @page_title = 'Thanks — IE Sergei Poljanski' @page_desc = 'Your message has been received. A confirmation copy has been sent to your inbox.' diff --git a/test/app_test.rb b/test/app_test.rb index a4eb6ba..63c7ffa 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -40,6 +40,12 @@ class AppTest < Minitest::Test assert last_response.ok? end + def test_healthz + get '/healthz' + assert last_response.ok? + assert_equal 'ok', last_response.body + end + # --- contact form --------------------------------------------------------- def contact_params(over = {})