Sha256: a638bf7a47dce19ebcede171b46e2c3b36a4817f24ad6088a99efdd253a93ee7

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

Contents

module ActiveRecord::Turntable
  module ActiveRecordExt
    module ConnectionHandlerExtension
      extend ActiveSupport::Concern

      included do
        alias_method_chain :pool_for, :turntable
      end

      private

      # @note Override not to establish_connection destroy existing connection pool proxy object
      def pool_for_with_turntable(owner)
        owner_to_pool.fetch(owner.name) {
          if ancestor_pool = pool_from_any_process_for(owner)
            if ancestor_pool.is_a?(ActiveRecord::Turntable::PoolProxy)
              # Use same PoolProxy object
              owner_to_pool[owner.name] = ancestor_pool
            else
              # A connection was established in an ancestor process that must have
              # subsequently forked. We can't reuse the connection, but we can copy
              # the specification and establish a new connection with it.
              establish_connection owner, ancestor_pool.spec
            end
          else
            owner_to_pool[owner.name] = nil
          end
        }
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activerecord-turntable-2.0.4 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-2.0.3 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-2.0.2 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-2.0.1 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb
activerecord-turntable-2.0.0 lib/active_record/turntable/active_record_ext/connection_handler_extension.rb