Sha256: aeacdbe408eae597ae819714780f536f47337c0dafd7ff37cb81856a19368a33

Contents?: true

Size: 869 Bytes

Versions: 6

Compression:

Stored size: 869 Bytes

Contents

require 'fresh_connection/abstract_connection_manager'
require 'fresh_connection/connection_specification'

module FreshConnection
  class ConnectionManager < AbstractConnectionManager
    def initialize(*args)
      super

      spec = FreshConnection::ConnectionSpecification.new(spec_name).spec
      @pool = ActiveRecord::ConnectionAdapters::ConnectionPool.new(spec)
    end

    def replica_connection
      @pool.connection
    end

    def put_aside!
      return unless @pool.active_connection?

      conn = replica_connection
      return if conn.transaction_open?

      @pool.release_connection
      @pool.remove(conn)
      conn.disconnect!
    end

    def clear_all_connections!
      @pool.disconnect!
    end

    def recovery?
      c = replica_connection rescue nil
      return false if c && c.active?
      put_aside!
      true
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fresh_connection-2.4.4 lib/fresh_connection/connection_manager.rb
fresh_connection-2.4.3 lib/fresh_connection/connection_manager.rb
fresh_connection-2.4.2 lib/fresh_connection/connection_manager.rb
fresh_connection-2.4.1 lib/fresh_connection/connection_manager.rb
fresh_connection-2.4.0 lib/fresh_connection/connection_manager.rb
fresh_connection-2.4.0.rc4 lib/fresh_connection/connection_manager.rb