module ReplicaPools

Constants

VERSION

Public Class Methods

config() click to toggle source
# File lib/replica_pools.rb, line 24
def config
  @config ||= ReplicaPools::Config.new
end
current() click to toggle source
# File lib/replica_pools.rb, line 43
def current
  proxy.current
end
log(level, message) click to toggle source
# File lib/replica_pools.rb, line 64
def log(level, message)
  logger.send(level, "[ReplicaPools] #{message}")
end
logger() click to toggle source
# File lib/replica_pools.rb, line 68
def logger
  ActiveRecord::Base.logger || Logger.new(STDOUT)
end
next_replica!() click to toggle source
# File lib/replica_pools.rb, line 47
def next_replica!
  proxy.next_replica!
end
pools() click to toggle source
# File lib/replica_pools.rb, line 60
def pools
  Thread.current[:replica_pools] ||= ReplicaPools::Pools.new
end
proxy() click to toggle source
# File lib/replica_pools.rb, line 36
def proxy
  Thread.current[:replica_pools_proxy] ||= ReplicaPools::ConnectionProxy.new(
    ActiveRecord::Base,
    ReplicaPools.pools
  )
end
setup!() click to toggle source
# File lib/replica_pools.rb, line 28
def setup!
  ConnectionProxy.generate_safe_delegations

  ActiveRecord::Base.send(:extend, ReplicaPools::Hijack)

  log :info, "Proxy loaded with: #{pools.keys.join(', ')}"
end
with_leader() { || ... } click to toggle source
# File lib/replica_pools.rb, line 55
def with_leader
  raise LeaderDisabled.new if ReplicaPools.config.disable_leader
  proxy.with_leader{ yield }
end
with_pool(*a) { || ... } click to toggle source
# File lib/replica_pools.rb, line 51
def with_pool(*a)
  proxy.with_pool(*a){ yield }
end