Class: FreshConnection::ConnectionManager

Inherits:
AbstractConnectionManager show all
Defined in:
lib/fresh_connection/connection_manager.rb

Instance Attribute Summary

Attributes inherited from AbstractConnectionManager

#spec_name

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ConnectionManager

Returns a new instance of ConnectionManager.



7
8
9
10
11
12
# File 'lib/fresh_connection/connection_manager.rb', line 7

def initialize(*args)
  super

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

Instance Method Details

#clear_all_connections!Object



29
30
31
# File 'lib/fresh_connection/connection_manager.rb', line 29

def clear_all_connections!
  @pool.disconnect!
end

#put_aside!Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/fresh_connection/connection_manager.rb', line 18

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

#recovery?Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/fresh_connection/connection_manager.rb', line 33

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

#replica_connectionObject



14
15
16
# File 'lib/fresh_connection/connection_manager.rb', line 14

def replica_connection
  @pool.connection
end