module Sequel::ConnectionPool::ClassMethods
Class methods used to return an appropriate pool subclass, separated into a module for easier overridding by extensions.
Public Instance Methods
get_pool(db, opts = OPTS)
click to toggle source
Return a pool subclass instance based on the given options. If a :pool_class
option is provided is provided, use that pool class, otherwise use a new instance of an appropriate pool subclass based on the SEQUEL_DEFAULT_CONNECTION_POOL
environment variable if set, or the :single_threaded
and :servers
options, otherwise.
# File lib/sequel/connection_pool.rb 48 def get_pool(db, opts = OPTS) 49 connection_pool_class(opts).new(db, opts) 50 end
Private Instance Methods
connection_pool_class(opts)
click to toggle source
Return a connection pool class based on the given options.
# File lib/sequel/connection_pool.rb 55 def connection_pool_class(opts) 56 if pc = opts[:pool_class] 57 unless pc.is_a?(Class) 58 unless name = POOL_CLASS_MAP[pc] 59 raise Sequel::Error, "unsupported connection pool type, please pass appropriate class as the :pool_class option" 60 end 61 62 require_relative "connection_pool/#{pc}" 63 pc = Sequel.const_get(name) 64 end 65 66 pc 67 elsif pc = ENV['SEQUEL_DEFAULT_CONNECTION_POOL'] 68 pc = "sharded_#{pc}" if opts[:servers] && !pc.start_with?('sharded_') 69 connection_pool_class(:pool_class=>pc) 70 else 71 pc = if opts[:single_threaded] 72 opts[:servers] ? :sharded_single : :single 73 # :nocov: 74 elsif RUBY_VERSION >= '3.4' # SEQUEL6 or maybe earlier switch to 3.2 75 opts[:servers] ? :sharded_timed_queue : :timed_queue 76 # :nocov: 77 else 78 opts[:servers] ? :sharded_threaded : :threaded 79 end 80 81 connection_pool_class(:pool_class=>pc) 82 end 83 end