nsq-cluster 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 407a8edf0a722a04596027ceb17c4d40f8aac645
4
- data.tar.gz: 7d8dceffa67428857cc8b976237669cd6ea8767a
3
+ metadata.gz: 2b0210ee2dd176e7c365d50c306c1882a5f93c7b
4
+ data.tar.gz: 46e60982e791fa040eae65148ba328776c231665
5
5
  SHA512:
6
- metadata.gz: f490a6fff8299fc87ea9c326620c4cdf92bb1882a145903a4ae7e453e9a8148e9e204229719d220b8477e0974f243719f4e9edae104d7ca0fce6df9ad6706a51
7
- data.tar.gz: f0b4e52afbac781ae6f7ff97d3f9c3cb7cbee108b74df63d631fc44ac46bce95321142e8d42e34d9deb7b897f39bb51d0209c13da9573e9ca337275ca8be50c5
6
+ metadata.gz: 85b1965782495a9c16197da9429545adeeeb74ed6f4109132a0b79a1369fd1863e753edc67ffc3e416875d64fa893dda1bb68708d06b9f528c2be56277ca1e03
7
+ data.tar.gz: 56927a22f30067f85320cdd988a69cbfd7d368b9910486255ede412c2e0c8c967220553c81fdce43e52f0f56395bb431ee1d496b10176de506e592b1ea0ae25f
data/bin/nsq-cluster CHANGED
@@ -30,6 +30,7 @@ cluster.block_until_running
30
30
  Signal.trap('INT') do
31
31
  print 'Shutting down ... '
32
32
  cluster.destroy
33
+ cluster.block_until_stopped
33
34
  puts 'done'
34
35
  exit
35
36
  end
@@ -1,3 +1,5 @@
1
+ require 'sys/proctable'
2
+
1
3
  require_relative 'process_wrapper'
2
4
 
3
5
  class Nsqadmin < ProcessWrapper
@@ -13,6 +15,14 @@ class Nsqadmin < ProcessWrapper
13
15
  end
14
16
 
15
17
 
18
+ def stop
19
+ Sys::ProcTable.ps.select{|pe| pe.ppid == @pid}.each do |child_pid|
20
+ Process.kill('TERM', child_pid)
21
+ end
22
+ super
23
+ end
24
+
25
+
16
26
  def command
17
27
  'nsqadmin'
18
28
  end
@@ -53,6 +53,17 @@ class ProcessWrapper
53
53
  def block_until_running
54
54
  if respond_to?(:http_port) && respond_to?(:host)
55
55
  wait_for_http_port(http_port, host)
56
+ else
57
+ raise "Can't block without http port and host"
58
+ end
59
+ end
60
+
61
+
62
+ def block_until_stopped
63
+ if respond_to?(:http_port) && respond_to?(:host)
64
+ wait_for_no_http_port(http_port, host)
65
+ else
66
+ raise "Can't block without http port and host"
56
67
  end
57
68
  end
58
69
 
@@ -74,4 +85,18 @@ class ProcessWrapper
74
85
  end
75
86
  end
76
87
  end
88
+
89
+
90
+ def wait_for_no_http_port(port, host)
91
+ port_closed = false
92
+ until port_closed do
93
+ begin
94
+ Net::HTTP.get_response(URI("http://#{host}:#{port}/ping"))
95
+ sleep HTTPCHECK_INTERVAL
96
+ rescue Errno::ECONNREFUSED
97
+ puts "HTTP port #{port} stopped responding to /ping." unless @silent
98
+ port_closed = true
99
+ end
100
+ end
101
+ end
77
102
  end
data/lib/nsq-cluster.rb CHANGED
@@ -73,7 +73,7 @@ class NsqCluster
73
73
 
74
74
 
75
75
  def destroy
76
- (@nsqd + @nsqlookupd).each { |d| d.destroy }
76
+ all_services.each{|s| s.destroy}
77
77
  end
78
78
 
79
79
 
@@ -91,7 +91,20 @@ class NsqCluster
91
91
  puts "Cluster launched." unless @silent
92
92
  end
93
93
  rescue Timeout::Error
94
- puts "ERROR: Cluster did not fully launch within #{timeout} seconds."
94
+ raise "Cluster did not fully launch within #{timeout} seconds."
95
+ end
96
+ end
97
+
98
+
99
+ def block_until_stopped(timeout = 10)
100
+ puts "Waiting for cluster to stop..." unless @silent
101
+ begin
102
+ Timeout::timeout(timeout) do
103
+ all_services.each{|service| service.block_until_stopped}
104
+ puts "Cluster stopped." unless @silent
105
+ end
106
+ rescue Timeout::Error
107
+ raise "Cluster did not fully stop within #{timeout} seconds."
95
108
  end
96
109
  end
97
110
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsq-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wistia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-18 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sys-proctable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: fakeweb
15
29
  requirement: !ruby/object:Gem::Requirement