Class: Pluggy::ConnectionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/pluggy/connection_manager.rb

Overview

Keep-alive Net::HTTP pool, one instance per thread (Net::HTTP objects are not thread-safe), keyed by Configuration#connection_key.

After a fork, sockets inherited from the parent are unusable. Call Pluggy::ConnectionManager.current.clear! in your after_fork hook (Puma, Unicorn, Sidekiq).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnectionManager

Returns a new instance of ConnectionManager.



18
19
20
# File 'lib/pluggy/connection_manager.rb', line 18

def initialize
  @pool = {}
end

Class Method Details

.currentObject



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

def self.current
  Thread.current[:pluggy_connection_manager] ||= new
end

Instance Method Details

#clear!Object



26
27
28
29
30
31
32
33
# File 'lib/pluggy/connection_manager.rb', line 26

def clear!
  @pool.each_value do |http|
    http.finish if http.started?
  rescue IOError, SystemCallError
    # Already dead; nothing to close.
  end
  @pool.clear
end

#connection_for(config) ⇒ Object



22
23
24
# File 'lib/pluggy/connection_manager.rb', line 22

def connection_for(config)
  @pool[config.connection_key] ||= build(config)
end