Class: Repctl::Client
- Inherits:
-
Mysql2::Client
- Object
- Mysql2::Client
- Repctl::Client
show all
- Includes:
- Servers
- Defined in:
- lib/repctl/mysql_admin.rb
Constant Summary
collapse
- @@clients =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Servers
#all_instances, #all_live_instances, #all_live_servers, #all_servers, #get_mysqld_pid, #instance_for, #live?, #mysqld_running?, #server_for_instance
Constructor Details
#initialize(instance, opts) ⇒ Client
Returns a new instance of Client.
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/repctl/mysql_admin.rb', line 12
def initialize(instance, opts)
@instance = instance
server = server_for_instance(@instance)
options = {
:host => server['hostname'],
:username => "root",
:port => server['port'],
:password => Config::ROOT_PASSWORD
}
options.delete(:password) if opts[:no_password]
@client = Mysql2::Client.new(options)
super(@client)
end
|
Class Method Details
.open(instance, opts = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/repctl/mysql_admin.rb', line 26
def self.open(instance, opts = {})
timeout = opts[:timeout] || 10
opts.delete(:timeout)
begin
instance = Integer(instance)
rescue Mysql2::Error => e
puts "Instance value <#{instance}> is invalid."
else
timeout = Integer(timeout)
while timeout >= 0
begin
@@clients[instance] ||= Client.new(instance, opts)
break
rescue Mysql2::Error => e
puts "#{e.message}, retrying connection to instance #{instance}..."
sleep 1
timeout -= 1
end
end
end
@@clients[instance]
end
|
Instance Method Details
#close ⇒ Object
50
51
52
53
|
# File 'lib/repctl/mysql_admin.rb', line 50
def close
@@clients[@instance] = nil
@client.close
end
|
#reset ⇒ Object
55
56
57
58
59
|
# File 'lib/repctl/mysql_admin.rb', line 55
def reset
@client.close
@@clients[@instance] = nil
Client.open(@instance)
end
|