Sha256: 596260f7c40c625c8020358c72a33d599b76ec9baf956f6af8be2302920aaacc

Contents?: true

Size: 899 Bytes

Versions: 14

Compression:

Stored size: 899 Bytes

Contents

# frozen_string_literal: true
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

14 entries across 14 versions & 1 rubygems

Version Path
fresh_connection-3.1.3 lib/fresh_connection/connection_manager.rb
fresh_connection-3.1.2 lib/fresh_connection/connection_manager.rb
fresh_connection-3.1.1 lib/fresh_connection/connection_manager.rb
fresh_connection-3.1.1.rc1 lib/fresh_connection/connection_manager.rb
fresh_connection-3.1.0 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.3 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.2 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.2.rc1 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.1 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.1.rc2 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.1.rc1 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.0 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.0.rc2 lib/fresh_connection/connection_manager.rb
fresh_connection-3.0.0.rc1 lib/fresh_connection/connection_manager.rb