Class: BatsdDash::ConnectionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/batsd-dash/connection_pool.rb

Defined Under Namespace

Classes: Client

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.poolObject (readonly)

Returns the value of attribute pool.



11
12
13
# File 'lib/batsd-dash/connection_pool.rb', line 11

def pool
  @pool
end

.settingsObject

Returns the value of attribute settings.



10
11
12
# File 'lib/batsd-dash/connection_pool.rb', line 10

def settings
  @settings
end

Class Method Details

.close_connection_poolObject



33
34
35
36
# File 'lib/batsd-dash/connection_pool.rb', line 33

def close_connection_pool
  @pool.close if @pool
  @pool = nil
end

.initialize_connection_poolObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/batsd-dash/connection_pool.rb', line 13

def initialize_connection_pool
  # default settings (which are defaults from batsd itself)
  @settings ||= { host: 'localhost', port: 8127, pool_size: 4 }

  if @reconnect_timer
    @reconnect_timer.cancel
    @reconnect_timer = nil
  end

  begin
    @pool = EventMachine::Synchrony::ConnectionPool.new(size: settings[:pool_size]) do
      Client.new(settings[:host], settings[:port])
    end

  rescue Exception => e
    warn "Connection Pool Error: #{e.message}"

  end
end

.start_reconnect_timerObject



38
39
40
41
42
43
# File 'lib/batsd-dash/connection_pool.rb', line 38

def start_reconnect_timer
  unless @reconnect_timer
    # try to reconnect every 30 seconds
    @reconnect_timer = EventMachine::Synchrony.add_timer(30) { initialize_connection_pool }
  end
end