Skip to content

Instantly share code, notes, and snippets.

@troelskn troelskn/db.rake
Last active Jan 28, 2019

Embed
What would you like to do?
Wait for db. Useful in a dockerized setup
namespace :db do
desc "Wait for db. Used for initial boot up"
task wait: :environment do
puts "*** Giving DB time to boot"
catch :done do
10.times do
Timeout.timeout(1) do
begin
ActiveRecord::Base.establish_connection
ActiveRecord::Base.connection.execute("SELECT NOW()")
puts "*** DB responded"
throw :done
rescue Timeout::Error, PG::ConnectionBad, Mysql2::Error, ActiveRecord::NoDatabaseError => err
puts err
end
end
sleep 1
end
fail "Did not get a connection"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.