Class: Nsqadmin

Inherits:
ProcessWrapper show all
Defined in:
lib/nsq-cluster/nsqadmin.rb

Constant Summary

Constants inherited from ProcessWrapper

ProcessWrapper::HTTPCHECK_INTERVAL

Instance Attribute Summary collapse

Attributes inherited from ProcessWrapper

#pid

Instance Method Summary collapse

Methods inherited from ProcessWrapper

#another_instance_is_running?, #block_until_running, #block_until_stopped, #destroy, #output, #running?, #start

Constructor Details

#initialize(opts = {}, verbose = false) ⇒ Nsqadmin

Returns a new instance of Nsqadmin.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/nsq-cluster/nsqadmin.rb', line 9

def initialize(opts = {}, verbose = false)
  super

  @host = '127.0.0.1'
  @http_port = opts.delete(:http_port) || 4171
  @lookupd = opts.delete(:nsqlookupd) || []

  @extra_args = opts.map do |key, value|
    "--#{key.to_s.gsub('_', '-')}=#{value}"
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/nsq-cluster/nsqadmin.rb', line 7

def host
  @host
end

#http_portObject (readonly)

Returns the value of attribute http_port.



7
8
9
# File 'lib/nsq-cluster/nsqadmin.rb', line 7

def http_port
  @http_port
end

Instance Method Details

#argsObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nsq-cluster/nsqadmin.rb', line 35

def args
  base_args = [
    %Q(--http-address=#{@host}:#{@http_port})
  ]

  lookupd_args = @lookupd.map do |ld|
    %Q(--lookupd-http-address=#{ld.host}:#{ld.http_port})
  end

  base_args + @extra_args + lookupd_args
end

#commandObject



30
31
32
# File 'lib/nsq-cluster/nsqadmin.rb', line 30

def command
  'nsqadmin'
end

#stop(opts = {}) ⇒ Object



22
23
24
25
26
27
# File 'lib/nsq-cluster/nsqadmin.rb', line 22

def stop(opts = {})
  Sys::ProcTable.ps.select{|pe| pe.ppid == @pid}.each do |child_pid|
    Process.kill('TERM', child_pid)
  end
  super
end