Sha256: 64409652cecdbd271c827212bdafe8f506c98b5ff1fb29e500d17f0125535638

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

module DistributeReads
  module AppropriatePool
    def _appropriate_pool(*args)
      if Thread.current[:distribute_reads]
        if Thread.current[:distribute_reads][:replica]
          if @slave_pool.completely_blacklisted?
            raise DistributeReads::NoReplicasAvailable, "No replicas available" if Thread.current[:distribute_reads][:failover] == false
            DistributeReads.log "No replicas available. Falling back to master pool."
            @master_pool
          else
            @slave_pool
          end
        elsif Thread.current[:distribute_reads][:primary] || needs_master?(*args) || (blacklisted = @slave_pool.completely_blacklisted?)
          if blacklisted
            if Thread.current[:distribute_reads][:failover] == false
              raise DistributeReads::NoReplicasAvailable, "No replicas available"
            else
              DistributeReads.log "No replicas available. Falling back to master pool."
            end
          end
          stick_to_master(*args) if DistributeReads.by_default
          @master_pool
        elsif in_transaction?
          @master_pool
        else
          @slave_pool
        end
      elsif !DistributeReads.by_default
        @master_pool
      else
        super
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
distribute_reads-0.5.0 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.4.0 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.3.5 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.3.4 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.3.3 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.3.2 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.3.1 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.3.0 lib/distribute_reads/appropriate_pool.rb
distribute_reads-0.2.4 lib/distribute_reads/appropriate_pool.rb