Skip to content

Instantly share code, notes, and snippets.

@csexton
Created May 18, 2016 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csexton/f0e0bee177e375cbda9e74c52f301b28 to your computer and use it in GitHub Desktop.
Save csexton/f0e0bee177e375cbda9e74c52f301b28 to your computer and use it in GitHub Desktop.
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