linqueta / rails-healthcheck

A simple way to configure a healthcheck route for a Rails application
MIT License
136 stars 10 forks source link

Healthcheck blows up if database doesn't exist #61

Closed epugh closed 3 years ago

epugh commented 3 years ago

I was testing hitting the /healthcheck point, and I decided to kill the database with a ps kill -9, and now the error raised is a "ActiveRecord::ConnectionNotEstablished ". I was expecting to instead hit the /healthcheck and get back a 503 error!

Likewise, when I had a pending migration, I got a message about it instead of the healthcheck point rendering:

Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=development
You have 1 pending migration:
20210907145957_bob.rb
linqueta commented 3 years ago

Hey man, I'll test what you did to see better how your scenario works.

epugh commented 3 years ago

Thanks! Here is my PR to Quepid that has this gem, which ironically is number 404 ;-) https://github.com/o19s/quepid/pull/404

Let me know if you need help reproducing it on the PR!

epugh commented 3 years ago

@linqueta I had a thought... Was it working the way I saw it because I was running Rails in DEV mode? If I ran it in PRODUCTION mode, would the healthcheck have returned the nicely formatted message instead?

epugh commented 3 years ago

Yep.. if you are running in PROD mode you get what you expected!


code | 503
-- | --
errors |  
0 |  
name | "migrations"
exception | "ActiveRecord::ConnectionNotEstablished"
message | "Unknown MySQL server host 'mysql' (-2)"
1 |  
name | "database"
exception | "ActiveRecord::ConnectionNotEstablished"
message | "Unknown MySQL server host 'mysql' (-2)"
epugh commented 3 years ago

I think this is worth documenting!

linqueta commented 3 years ago

You are right man, I tried what you said and it's truth. So, I'll add a tip in README to guide people about it. If you want/may build this pull request it'll be awesome!