Sha256: b25fd78afee9ba6cf9487750202eb6651f3953e43784bfc9c158d3946d398ff5
Contents?: true
Size: 1.09 KB
Versions: 3
Compression:
Stored size: 1.09 KB
Contents
module EbisuConnection class Slave attr_reader :hostname, :weight def initialize(conf, slave_group) case conf when String host, weight = conf.split(/\s*,\s*/) @hostname, port = host.split(/\s*:\s*/) when Hash @hostname = conf["host"] || conf[:host] weight = conf["weight"] || conf[:weight] port = conf["port"] || conf[:port] else raise ArgumentError, "slaves config is invalid" end spec = modify_spec(port) @connection_factory = FreshConnection::ConnectionFactory.new(slave_group, spec) @weight = (weight || 1).to_i end def connection @connection ||= @connection_factory.new_connection end def active? connection.active? end def disconnect! if @connection @connection.disconnect! @connection = nil end rescue end def modify_spec(port) modify_spec = {"host" => @hostname} return modify_spec unless port modify_spec["port"] = port.to_i if port.is_a?(Integer) || !port.empty? modify_spec end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ebisu_connection-2.2.0 | lib/ebisu_connection/slave.rb |
ebisu_connection-2.1.0 | lib/ebisu_connection/slave.rb |
ebisu_connection-2.0.0 | lib/ebisu_connection/slave.rb |