nsq-cluster 0.2.5 → 0.2.7

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: 2b0210ee2dd176e7c365d50c306c1882a5f93c7b
4
- data.tar.gz: 46e60982e791fa040eae65148ba328776c231665
3
+ metadata.gz: b47dc619bd8a8ea2247893e68b3da23c6303b1f7
4
+ data.tar.gz: 852cfe562564cd6b793576ee17840e7b0de1e35b
5
5
  SHA512:
6
- metadata.gz: 85b1965782495a9c16197da9429545adeeeb74ed6f4109132a0b79a1369fd1863e753edc67ffc3e416875d64fa893dda1bb68708d06b9f528c2be56277ca1e03
7
- data.tar.gz: 56927a22f30067f85320cdd988a69cbfd7d368b9910486255ede412c2e0c8c967220553c81fdce43e52f0f56395bb431ee1d496b10176de506e592b1ea0ae25f
6
+ metadata.gz: a7306f2913bfd847d960f1cab03918ab57a6cdc21a84f6c3adecdac7d2dc59416650c244c21d5e4e77fd42ddc2634bf647b9d503e85fda716d74592adf144f09
7
+ data.tar.gz: 1f886a10b6cc6a8ecedf32c38b4b196ca9e297cf29e42ddaec22dba1e98d1c90681b1fa531b8bcacbda019e81f8b6e6815b6264f8862520f94adb493a22d3707
data/lib/nsq-cluster.rb CHANGED
@@ -36,8 +36,14 @@ class NsqCluster
36
36
  @nsqd = create_nsqds(opts[:nsqd_count], opts[:nsqd_options])
37
37
  @nsqadmin = create_nsqadmin if opts[:nsqadmin]
38
38
 
39
- # start everything!
40
- all_services.each { |d| d.start }
39
+ begin
40
+ # start everything!
41
+ all_services.each { |d| d.start }
42
+ rescue Exception => ex
43
+ # if we hit an error, stop everything that we started
44
+ destroy
45
+ raise ex
46
+ end
41
47
  end
42
48
 
43
49
 
@@ -8,7 +8,7 @@ class ProcessWrapper
8
8
 
9
9
 
10
10
  def start
11
- raise "#{command} is already running" if running?
11
+ raise "#{command} is already running" if running? || another_instance_is_running?
12
12
  @pid = spawn(command, *args, [:out, :err] => output)
13
13
  end
14
14
 
@@ -31,6 +31,15 @@ class ProcessWrapper
31
31
  end
32
32
 
33
33
 
34
+ def another_instance_is_running?
35
+ if respond_to?(:http_port)
36
+ http_port_open?
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+
34
43
  def command
35
44
  raise 'you have to override this in a subclass, hotshot'
36
45
  end
@@ -52,7 +61,7 @@ class ProcessWrapper
52
61
 
53
62
  def block_until_running
54
63
  if respond_to?(:http_port) && respond_to?(:host)
55
- wait_for_http_port(http_port, host)
64
+ wait_for_http_port
56
65
  else
57
66
  raise "Can't block without http port and host"
58
67
  end
@@ -61,7 +70,7 @@ class ProcessWrapper
61
70
 
62
71
  def block_until_stopped
63
72
  if respond_to?(:http_port) && respond_to?(:host)
64
- wait_for_no_http_port(http_port, host)
73
+ wait_for_no_http_port
65
74
  else
66
75
  raise "Can't block without http port and host"
67
76
  end
@@ -69,34 +78,33 @@ class ProcessWrapper
69
78
 
70
79
 
71
80
  private
72
- def wait_for_http_port(port, host)
73
- port_open = false
74
- until port_open do
75
- begin
76
- response = Net::HTTP.get_response(URI("http://#{host}:#{port}/ping"))
77
- if response.is_a?(Net::HTTPSuccess)
78
- port_open = true
79
- puts "HTTP port #{port} responded to /ping." unless @silent
80
- else
81
- sleep HTTPCHECK_INTERVAL
82
- end
83
- rescue Errno::ECONNREFUSED
84
- sleep HTTPCHECK_INTERVAL
85
- end
81
+ def wait_for_http_port
82
+ until http_port_open? do
83
+ sleep HTTPCHECK_INTERVAL
86
84
  end
85
+ puts "HTTP port #{http_port} responded to /ping." unless @silent
87
86
  end
88
87
 
89
88
 
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
89
+ def wait_for_no_http_port
90
+ until !http_port_open? do
91
+ sleep HTTPCHECK_INTERVAL
92
+ end
93
+ puts "HTTP port #{http_port} stopped responding to /ping." unless @silent
94
+ end
95
+
96
+
97
+ def http_port_open?
98
+ begin
99
+ response = Net::HTTP.get_response(URI("http://#{host}:#{http_port}/ping"))
100
+ if response.is_a?(Net::HTTPSuccess)
101
+ true
102
+ else
103
+ false
99
104
  end
105
+ rescue Errno::ECONNREFUSED
106
+ false
100
107
  end
101
108
  end
109
+
102
110
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsq-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
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-25 00:00:00.000000000 Z
11
+ date: 2014-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-proctable