Class: LitmusPaper::Dependency::HaproxyBackends

Inherits:
Object
  • Object
show all
Includes:
HaproxyUtil
Defined in:
lib/litmus_paper/dependency/haproxy_backends.rb

Instance Method Summary collapse

Methods included from HaproxyUtil

#_fetch_stats, #_get_stats, #_parse_stats, #find_backend, #find_servers

Constructor Details

#initialize(domain_socket, cluster, options = {}) ⇒ HaproxyBackends

Returns a new instance of HaproxyBackends.



8
9
10
11
12
# File 'lib/litmus_paper/dependency/haproxy_backends.rb', line 8

def initialize(domain_socket, cluster, options = {})
  @domain_socket = domain_socket
  @cluster = cluster
  @timeout = options.fetch(:timeout_seconds, 2)
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/litmus_paper/dependency/haproxy_backends.rb', line 14

def available?
  backend = find_backend(@domain_socket, @timeout, @cluster)

  if backend['weight'].to_i == 0
    LitmusPaper.logger.info(
      "HAProxy available check failed for #{@cluster}, status: #{backend['status']}, weight: #{backend['weight']}"
    )
    return false
  end
  return true
rescue Timeout::Error
  LitmusPaper.logger.info("HAProxy available check timed out for #{@cluster}")
  false
rescue => e
  LitmusPaper.logger.info("HAProxy available check failed for #{@cluster} with #{e.message}")
  false
end

#to_sObject



32
33
34
# File 'lib/litmus_paper/dependency/haproxy_backends.rb', line 32

def to_s
  "Dependency::HaproxyBackends(#{@domain_socket}, #{@cluster})"
end