lib/octopus/proxy.rb in ar-octopus-0.0.30 vs lib/octopus/proxy.rb in ar-octopus-0.1.0
- old
+ new
@@ -9,10 +9,17 @@
def initialize_shards(config)
@shards = {}
@groups = {}
@shards[:master] = ActiveRecord::Base.connection_pool()
@current_shard = :master
+
+ if !config.nil? && config.has_key?("verify_connection")
+ @verify_connection = config["verify_connection"]
+ else
+ @verify_connection = false
+ end
+
if !config.nil?
@entire_sharded = config['entire_sharded']
shards_config = config[Octopus.rails_env()]
end
@@ -69,9 +76,10 @@
def current_model=(model)
@current_model = model.is_a?(ActiveRecord::Base) ? model.class : model
end
def select_connection()
+ @shards[shard_name].verify_active_connections! if @verify_connection
@shards[shard_name].connection()
end
def shard_name
current_shard.is_a?(Array) ? current_shard.first : current_shard