nsq-cluster 0.2.7 → 0.3.0

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: b47dc619bd8a8ea2247893e68b3da23c6303b1f7
4
- data.tar.gz: 852cfe562564cd6b793576ee17840e7b0de1e35b
3
+ metadata.gz: 5fbeebffe7f886384eb99c3c7bbb3a07a66dfb58
4
+ data.tar.gz: ef5db16daa418743ba8b9e32c3529cfc526b017b
5
5
  SHA512:
6
- metadata.gz: a7306f2913bfd847d960f1cab03918ab57a6cdc21a84f6c3adecdac7d2dc59416650c244c21d5e4e77fd42ddc2634bf647b9d503e85fda716d74592adf144f09
7
- data.tar.gz: 1f886a10b6cc6a8ecedf32c38b4b196ca9e297cf29e42ddaec22dba1e98d1c90681b1fa531b8bcacbda019e81f8b6e6815b6264f8862520f94adb493a22d3707
6
+ metadata.gz: 298fd3698cc0d43ec147f2740c88ec68c4c5c0fc19c3c180440d65dcce4777a6177b38247da7429cecba540a5a17c7c4a35d02afb34a2a49630fed193bec5fbc
7
+ data.tar.gz: 22ffb6980ead07c4397e4116fb54606a5a8df284989ee247bf80f7959c358d5598546ec23de6dca8bae76d3dfe10a2263b55d66856f26fed9e74474121775de9
data/README.md CHANGED
@@ -6,12 +6,15 @@ Easily start up a local NSQ cluster. This is great for testing.
6
6
  # Start a cluster of 3 nsqd's and 2 nsqlookupd's
7
7
  cluster = NsqCluster.new(nsqd_count: 3, nsqlookupd_count: 2)
8
8
 
9
- # Optionaally, block until the cluster is up and running
9
+ # Optionally, block until the cluster is up and running
10
10
  cluster.block_until_running
11
11
 
12
12
  # Stop the 3rd nsqd instance
13
13
  cluster.nsqd.last.stop
14
14
 
15
+ # Wait until it's stopped
16
+ cluster.nsqd.last.block_until_stopped
17
+
15
18
  # Start it back up again
16
19
  cluster.nsqd.last.start
17
20
 
@@ -19,6 +22,21 @@ cluster.nsqd.last.start
19
22
  cluster.destroy
20
23
  ```
21
24
 
25
+ ## Flags for nsqd and nsqlookupd
26
+
27
+ Optionally, you can pass in flags for nsqd and nsqlookupd like this:
28
+
29
+ ```ruby
30
+ NsqCluster.new(
31
+ nsqd_count: 1,
32
+ nsqlookupd_count: 1,
33
+ nsqd_options: { verbose: true },
34
+ nsqlookupd_options: { verbose: true }
35
+ )
36
+ ```
37
+
38
+ ## Send commands to nsqd
39
+
22
40
  Available methods that map to [`nsqd`'s](http://nsq.io/components/nsqd.html) HTTP endpoints.
23
41
 
24
42
  ```ruby
@@ -49,6 +67,8 @@ nsqd.ping
49
67
  nsqd.info
50
68
  ```
51
69
 
70
+ ## Send commands to nsqlookup
71
+
52
72
  Available methods that map to [`nsqlookupd`'s](http://nsq.io/components/nsqlookupd.html) HTTP endpoints.
53
73
 
54
74
  ```ruby
@@ -78,4 +98,4 @@ nsqlookupd.ping
78
98
 
79
99
  # Get general info
80
100
  nsqlookupd.info
81
- ```
101
+ ```
data/bin/nsq-cluster CHANGED
@@ -9,7 +9,7 @@ options = {
9
9
  nsqd_count: 1,
10
10
  nsqlookupd_count: 1,
11
11
  nsqadmin: true,
12
- silent: false
12
+ verbose: true
13
13
  }
14
14
 
15
15
  OptionParser.new do |opts|
data/lib/nsq-cluster.rb CHANGED
@@ -28,10 +28,10 @@ class NsqCluster
28
28
  nsqd_count: 0,
29
29
  nsqadmin: false,
30
30
  nsqd_options: {},
31
- silent: true
31
+ verbose: false
32
32
  }.merge(opts)
33
- @silent = opts[:silent]
34
33
 
34
+ @verbose = opts[:verbose]
35
35
  @nsqlookupd = create_nsqlookupds(opts[:nsqlookupd_count], opts[:nsqdlookupd_options])
36
36
  @nsqd = create_nsqds(opts[:nsqd_count], opts[:nsqd_options])
37
37
  @nsqadmin = create_nsqadmin if opts[:nsqadmin]
@@ -49,31 +49,35 @@ class NsqCluster
49
49
 
50
50
  def create_nsqlookupds(count, options)
51
51
  (0...count).map do |idx|
52
- Nsqlookupd.new(options.merge({
53
- tcp_port: 4160 + idx * 2,
54
- http_port: 4161 + idx * 2,
55
- silent: @silent
56
- }))
52
+ Nsqlookupd.new(
53
+ options.merge({
54
+ tcp_port: 4160 + idx * 2,
55
+ http_port: 4161 + idx * 2
56
+ }),
57
+ @verbose
58
+ )
57
59
  end
58
60
  end
59
61
 
60
62
 
61
63
  def create_nsqds(count, options)
62
64
  (0...count).map do |idx|
63
- Nsqd.new(options.merge({
64
- tcp_port: 4150 + idx * 2,
65
- http_port: 4151 + idx * 2,
66
- nsqlookupd: @nsqlookupd,
67
- silent: @silent
68
- }))
65
+ Nsqd.new(
66
+ options.merge({
67
+ tcp_port: 4150 + idx * 2,
68
+ http_port: 4151 + idx * 2,
69
+ nsqlookupd: @nsqlookupd,
70
+ }),
71
+ @verbose
72
+ )
69
73
  end
70
74
  end
71
75
 
72
76
 
73
77
  def create_nsqadmin
74
78
  Nsqadmin.new(
75
- nsqlookupd: @nsqlookupd,
76
- silent: @silent
79
+ { nsqlookupd: @nsqlookupd },
80
+ @verbose
77
81
  )
78
82
  end
79
83
 
@@ -90,11 +94,11 @@ class NsqCluster
90
94
 
91
95
 
92
96
  def block_until_running(timeout = 3)
93
- puts "Waiting for cluster to launch..." unless @silent
97
+ puts "Waiting for cluster to launch..." if @verbose
94
98
  begin
95
99
  Timeout::timeout(timeout) do
96
100
  all_services.each {|service| service.block_until_running}
97
- puts "Cluster launched." unless @silent
101
+ puts "Cluster launched." if @verbose
98
102
  end
99
103
  rescue Timeout::Error
100
104
  raise "Cluster did not fully launch within #{timeout} seconds."
@@ -103,11 +107,11 @@ class NsqCluster
103
107
 
104
108
 
105
109
  def block_until_stopped(timeout = 10)
106
- puts "Waiting for cluster to stop..." unless @silent
110
+ puts "Waiting for cluster to stop..." if @verbose
107
111
  begin
108
112
  Timeout::timeout(timeout) do
109
113
  all_services.each{|service| service.block_until_stopped}
110
- puts "Cluster stopped." unless @silent
114
+ puts "Cluster stopped." if @verbose
111
115
  end
112
116
  rescue Timeout::Error
113
117
  raise "Cluster did not fully stop within #{timeout} seconds."
@@ -6,12 +6,16 @@ class Nsqadmin < ProcessWrapper
6
6
 
7
7
  attr_reader :host, :http_port
8
8
 
9
- def initialize(opts = {})
9
+ def initialize(opts = {}, verbose = false)
10
+ super
11
+
10
12
  @host = '127.0.0.1'
11
- @http_port = opts[:http_port] || 4171
12
- @lookupd = opts[:nsqlookupd] || []
13
+ @http_port = opts.delete(:http_port) || 4171
14
+ @lookupd = opts.delete(:nsqlookupd) || []
13
15
 
14
- super
16
+ @extra_args = opts.map do |key, value|
17
+ "--#{key.to_s.gsub('_', '-')}=#{value}"
18
+ end
15
19
  end
16
20
 
17
21
 
@@ -37,7 +41,7 @@ class Nsqadmin < ProcessWrapper
37
41
  %Q(--lookupd-http-address=#{ld.host}:#{ld.http_port})
38
42
  end
39
43
 
40
- base_args + lookupd_args
44
+ base_args + @extra_args + lookupd_args
41
45
  end
42
46
 
43
47
  end
@@ -9,18 +9,21 @@ class Nsqd < ProcessWrapper
9
9
  attr_reader :host, :tcp_port, :http_port
10
10
 
11
11
 
12
- def initialize(opts = {})
13
- @host = opts[:host] || '127.0.0.1'
14
- @tcp_port = opts[:tcp_port] || 4150
15
- @http_port = opts[:http_port] || 4151
16
- @lookupd = opts[:nsqlookupd] || []
17
- @msg_timeout = opts[:msg_timeout] || '60s'
18
- @broadcast_address = opts[:broadcast_address] || @host
12
+ def initialize(opts = {}, verbose = false)
13
+ super
14
+
15
+ @host = opts.delete(:host) || '127.0.0.1'
16
+ @tcp_port = opts.delete(:tcp_port) || 4150
17
+ @http_port = opts.delete(:http_port) || 4151
18
+ @lookupd = opts.delete(:nsqlookupd) || []
19
+ @broadcast_address = opts.delete(:broadcast_address) || @host
20
+
21
+ @extra_args = opts.map do |key, value|
22
+ "--#{key.to_s.gsub('_', '-')}=#{value}"
23
+ end
19
24
 
20
25
  clear_data_directory
21
26
  create_data_directory
22
-
23
- super
24
27
  end
25
28
 
26
29
 
@@ -41,7 +44,6 @@ class Nsqd < ProcessWrapper
41
44
  %Q(--http-address=#{@host}:#{@http_port}),
42
45
  %Q(--data-path=#{data_path}),
43
46
  %Q(--worker-id=#{worker_id}),
44
- %Q(--msg-timeout=#{@msg_timeout}),
45
47
  %Q(--broadcast-address=#{@broadcast_address})
46
48
  ]
47
49
 
@@ -49,7 +51,7 @@ class Nsqd < ProcessWrapper
49
51
  %Q(--lookupd-tcp-address=#{ld.host}:#{ld.tcp_port})
50
52
  end
51
53
 
52
- base_args + lookupd_args
54
+ base_args + @extra_args + lookupd_args
53
55
  end
54
56
 
55
57
 
@@ -6,13 +6,17 @@ class Nsqlookupd < ProcessWrapper
6
6
 
7
7
  attr_reader :host, :tcp_port, :http_port
8
8
 
9
- def initialize(opts = {})
10
- @host = opts[:host] || '127.0.0.1'
11
- @tcp_port = opts[:tcp_port] || 4160
12
- @http_port = opts[:http_port] || 4161
13
- @broadcast_address = opts[:broadcast_address] || @host
14
-
9
+ def initialize(opts = {}, verbose = false)
15
10
  super
11
+
12
+ @host = opts.delete(:host) || '127.0.0.1'
13
+ @tcp_port = opts.delete(:tcp_port) || 4160
14
+ @http_port = opts.delete(:http_port) || 4161
15
+ @broadcast_address = opts.delete(:broadcast_address) || @host
16
+
17
+ @extra_args = opts.map do |key, value|
18
+ "--#{key.to_s.gsub('_', '-')}=#{value}"
19
+ end
16
20
  end
17
21
 
18
22
 
@@ -26,7 +30,7 @@ class Nsqlookupd < ProcessWrapper
26
30
  %Q(--tcp-address=#{@host}:#{@tcp_port}),
27
31
  %Q(--http-address=#{@host}:#{@http_port}),
28
32
  %Q(--broadcast-address=#{@broadcast_address})
29
- ]
33
+ ] + @extra_args
30
34
  end
31
35
 
32
36
 
@@ -1,9 +1,10 @@
1
1
  class ProcessWrapper
2
2
  HTTPCHECK_INTERVAL = 0.01
3
3
 
4
+ attr_reader :pid
4
5
 
5
- def initialize(opts = {})
6
- @silent = opts[:silent]
6
+ def initialize(opts = {}, verbose = false)
7
+ @verbose = verbose
7
8
  end
8
9
 
9
10
 
@@ -51,10 +52,10 @@ class ProcessWrapper
51
52
 
52
53
 
53
54
  def output
54
- if @silent
55
- '/dev/null'
56
- else
55
+ if @verbose
57
56
  :out
57
+ else
58
+ '/dev/null'
58
59
  end
59
60
  end
60
61
 
@@ -82,7 +83,7 @@ class ProcessWrapper
82
83
  until http_port_open? do
83
84
  sleep HTTPCHECK_INTERVAL
84
85
  end
85
- puts "HTTP port #{http_port} responded to /ping." unless @silent
86
+ puts "HTTP port #{http_port} responded to /ping." if @verbose
86
87
  end
87
88
 
88
89
 
@@ -90,20 +91,16 @@ class ProcessWrapper
90
91
  until !http_port_open? do
91
92
  sleep HTTPCHECK_INTERVAL
92
93
  end
93
- puts "HTTP port #{http_port} stopped responding to /ping." unless @silent
94
+ puts "HTTP port #{http_port} stopped responding to /ping." if @verbose
94
95
  end
95
96
 
96
97
 
97
98
  def http_port_open?
98
99
  begin
99
100
  response = Net::HTTP.get_response(URI("http://#{host}:#{http_port}/ping"))
100
- if response.is_a?(Net::HTTPSuccess)
101
- true
102
- else
103
- false
104
- end
101
+ return response.is_a?(Net::HTTPSuccess)
105
102
  rescue Errno::ECONNREFUSED
106
- false
103
+ return false
107
104
  end
108
105
  end
109
106
 
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.7
4
+ version: 0.3.0
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-28 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-proctable