Sha256: fe57fb15bc9153b06d373b4c0bd24c4fb8e5010fe67260af5bc3f3ed690dc333

Contents?: true

Size: 841 Bytes

Versions: 2

Compression:

Stored size: 841 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?
      return false if replica_connection.active?
      put_aside!
      true
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fresh_connection-2.4.0.rc3 lib/fresh_connection/connection_manager.rb
fresh_connection-2.4.0.rc1 lib/fresh_connection/connection_manager.rb