15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/docker/rails/cli/db_check.rb', line 15
def mysql
require 'rubygems'
require 'active_record'
require 'mysql2'
puts "\n"
connect_string = "#{options[:username]}@#{options[:host]}:#{options[:port]}"
printf "Waiting for confirmation of db service startup at #{connect_string}..."
last_message = ''
loop_limit = options[:count].to_i + 1
loop_limit.times do |i|
if i == loop_limit - 1
printf "failed to connect. #{last_message}\n\n\n"
raise "Failed to connect to db service at #{connect_string}. #{last_message}"
end
connection_options = {
adapter: 'mysql2',
host: options[:host],
port: options[:port],
username: options[:username]
}
connection_options[:password] = options[:password] unless options[:password].nil?
ActiveRecord::Base.establish_connection (connection_options)
connected =
begin
ActiveRecord::Base.connection_pool.with_connection { |con| con.active? }
rescue => e
last_message = "#{e.class.name}: #{e.message}"
false
end
printf '.'
if connected
printf 'connected.'
break
end
sleep 1
end
puts "\n"
end
|