class Philae::NSQClusterProbe

Constants

DEFAULT_HTTP_PORT

Attributes

name[R]
nsq_probes[R]

Public Class Methods

new(name, hosts, tls_context = nil, opts = {}) click to toggle source
# File lib/philae/nsq_cluster_probe.rb, line 31
def initialize(name, hosts, tls_context = nil, opts = {})
  raise ArgumentError, 'should have at least one host' if hosts.nil? || hosts.empty?

  @name = name
  @nsq_probes = hosts.map do |hostport|
    host, port = hostport.split(':')
    port = DEFAULT_HTTP_PORT if port.nil?
    next Philae::NSQProbe.new("#{name}-#{host}-#{port}", host, port, tls_context, opts)
  end
end
new_from_env(name, opts = {}) click to toggle source
# File lib/philae/nsq_cluster_probe.rb, line 10
def self.new_from_env(name, opts = {})
  if ENV['NSQD_HOSTS'].nil? || ENV['NSQD_HTTP_PORT'].nil?
    raise ArgumentError, 'no NSQD_HOSTS and NSQD_HTTP_PORT defined'
  end

  tls_context = nil
  if ENV['NSQD_TLS'] == 'true'
    tls_context = {
      cert: ENV['NSQD_TLS_CERT'],
      key: ENV['NSQD_TLS_KEY'],
      ca: ENV['NSQD_TLS_CACERT'],
    }
  end

  http_hosts = ENV['NSQD_HOSTS'].split(',').map do |host|
    host.split(':')[0] + ":#{ENV['NSQD_HTTP_PORT']}"
  end

  new(name, http_hosts, tls_context, opts)
end

Public Instance Methods

probes() click to toggle source
# File lib/philae/nsq_cluster_probe.rb, line 42
def probes
  @nsq_probes
end