Class: Clickhouse::Cluster
- Inherits:
- BasicObject
- Defined in:
- lib/clickhouse/cluster.rb
Instance Attribute Summary collapse
-
#pond ⇒ Object
readonly
Returns the value of attribute pond.
Instance Method Summary collapse
-
#initialize(config) ⇒ Cluster
constructor
A new instance of Cluster.
Constructor Details
#initialize(config) ⇒ Cluster
Returns a new instance of Cluster.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/clickhouse/cluster.rb', line 6 def initialize(config) config = config.dup urls = config.delete(:urls) || config.delete("urls") urls.collect!{|url| ::Clickhouse::Utils.normalize_url(url)} @pond = ::Pond.new :maximum_size => urls.size, :timeout => 5.0 block = ::Proc.new do url = (urls - pond.available.collect(&:url)).first || urls.sample ::Clickhouse::Connection.new(config.merge(:url => url)) end pond.instance_variable_set :@block, block pond.maximum_size.times do pond.available << block.call end pond.detach_if = ::Proc.new do |connection| begin connection.ping! false rescue true end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object (private)
34 35 36 37 38 39 40 |
# File 'lib/clickhouse/cluster.rb', line 34 def method_missing(*args, &block) pond.checkout do |connection| connection.send(*args, &block) end rescue ::Clickhouse::ConnectionError retry if pond.available.any? end |
Instance Attribute Details
#pond ⇒ Object (readonly)
Returns the value of attribute pond.
4 5 6 |
# File 'lib/clickhouse/cluster.rb', line 4 def pond @pond end |