Created
May 18, 2016 22:05
-
-
Save csexton/f0e0bee177e375cbda9e74c52f301b28 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class DatabaseCheck | |
def self.wait_for_connection | |
self.new.check(10) | |
end | |
def check(times) | |
times.times do | |
opts = Rails.configuration.database_configuration[Rails.env] | |
ActiveRecord::Base.establish_connection (opts) | |
connected = begin | |
ActiveRecord::Base.connection_pool.with_connection { |con| con.active? } | |
rescue => e | |
last_message = "#{e.class.name}: #{e.message}" | |
false | |
end | |
printf '.' | |
return true if connected | |
sleep 1 | |
end | |
false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment