Module: HotTub::KnownClients

Included in:
Pool, Sessions
Defined in:
lib/hot_tub/known_clients.rb

Constant Summary collapse

KNOWN_CLIENTS =
{
  "Excon::Connection" => {
    :close => :reset
  },
  "Net::HTTP" => {
    :close => lambda { |clnt|
      begin
        clnt.finish
      rescue IOError
        nil
      end
    }
  }
}

Instance Method Summary collapse

Instance Method Details

#clean_client(clnt) ⇒ Object

Attempts to clean the provided client, checking the options first for a clean block then checking the known clients



20
21
22
23
24
25
26
27
28
29
# File 'lib/hot_tub/known_clients.rb', line 20

def clean_client(clnt)
  if @clean_client
    begin
      perform_action(clnt,@clean_client)
    rescue => e
      HotTub.logger.error "[HotTub] There was an error cleaning one of your #{self.class.name} clients: #{e}" if HotTub.logger
    end
  end
  clnt
end

#close_client(clnt) ⇒ Object

Attempts to close the provided client, checking the options first for a close block then checking the known clients



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hot_tub/known_clients.rb', line 33

def close_client(clnt)
  @close_client = (known_client_action(clnt,:close) || false) if @close_client.nil?
  if @close_client
    begin
      perform_action(clnt,@close_client)
    rescue => e
      HotTub.logger.error "[HotTub] There was an error closing one of your #{self.class.name} clients: #{e}" if HotTub.logger
    end
  end
  nil
end

#reap_client?(clnt) ⇒ Boolean

Attempts to determine if a client should be reaped, block should return a boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hot_tub/known_clients.rb', line 46

def reap_client?(clnt)
  rc = false
  if @reap_client
    begin
      rc = perform_action(clnt,@reap_client)
    rescue => e
      HotTub.logger.error "[HotTub] There was an error reaping one of your #{self.class.name} clients: #{e}" if HotTub.logger
    end
  end
  rc
end