Class: Repctl::Client
- Inherits:
-
Mysql2::Client
- Object
- Mysql2::Client
- Repctl::Client
- Includes:
- Servers
- Defined in:
- lib/repctl/mysql_admin.rb
Constant Summary collapse
- @@clients =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(instance, opts) ⇒ Client
constructor
A new instance of Client.
- #reset ⇒ Object
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) = { :host => server['hostname'], :username => "root", :port => server['port'], :password => Config::ROOT_PASSWORD } .delete(:password) if opts[:no_password] @client = Mysql2::Client.new() 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.}, retrying connection to instance #{instance}..." # puts e.backtrace 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 |