Sha256: 059ee6e515811520a88c285d47e14ce3a26aabdb91361dfd3532748f68361e9e

Contents?: true

Size: 1.54 KB

Versions: 33

Compression:

Stored size: 1.54 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    class PoolConfig # :nodoc:
      include Mutex_m

      attr_reader :db_config, :connection_klass
      attr_accessor :schema_cache

      INSTANCES = ObjectSpace::WeakMap.new
      private_constant :INSTANCES

      class << self
        def discard_pools!
          INSTANCES.each_key(&:discard_pool!)
        end
      end

      def initialize(connection_klass, db_config)
        super()
        @connection_klass = connection_klass
        @db_config = db_config
        @pool = nil
        INSTANCES[self] = self
      end

      def connection_specification_name
        if connection_klass.is_a?(String)
          connection_klass
        elsif connection_klass.primary_class?
          "ActiveRecord::Base"
        else
          connection_klass.name
        end
      end

      def disconnect!
        ActiveSupport::ForkTracker.check!

        return unless @pool

        synchronize do
          return unless @pool

          @pool.automatic_reconnect = false
          @pool.disconnect!
        end

        nil
      end

      def pool
        ActiveSupport::ForkTracker.check!

        @pool || synchronize { @pool ||= ConnectionAdapters::ConnectionPool.new(self) }
      end

      def discard_pool!
        return unless @pool

        synchronize do
          return unless @pool

          @pool.discard!
          @pool = nil
        end
      end
    end
  end
end

ActiveSupport::ForkTracker.after_fork { ActiveRecord::ConnectionAdapters::PoolConfig.discard_pools! }

Version data entries

33 entries across 33 versions & 4 rubygems

Version Path
activerecord-6.1.7.10 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.9 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.8 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.7 lib/active_record/connection_adapters/pool_config.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.6 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.5 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.4 lib/active_record/connection_adapters/pool_config.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.3 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.2 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7.1 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.7 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.6.1 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.6 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.5.1 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.5 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.4.7 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.4.6 lib/active_record/connection_adapters/pool_config.rb
activerecord-6.1.4.5 lib/active_record/connection_adapters/pool_config.rb