nsq-cluster 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fbeebffe7f886384eb99c3c7bbb3a07a66dfb58
4
- data.tar.gz: ef5db16daa418743ba8b9e32c3529cfc526b017b
3
+ metadata.gz: 912e82c06fc1606ed7a0c6cfcef965b7c150db75
4
+ data.tar.gz: 73cbfdcfa92085899ade4fd397a3d12c4477d043
5
5
  SHA512:
6
- metadata.gz: 298fd3698cc0d43ec147f2740c88ec68c4c5c0fc19c3c180440d65dcce4777a6177b38247da7429cecba540a5a17c7c4a35d02afb34a2a49630fed193bec5fbc
7
- data.tar.gz: 22ffb6980ead07c4397e4116fb54606a5a8df284989ee247bf80f7959c358d5598546ec23de6dca8bae76d3dfe10a2263b55d66856f26fed9e74474121775de9
6
+ metadata.gz: 63c76b46b7f9d20c8e75e018f8514f5d5f713ea4d0467123a9c0cfa33ae76eaeb777d2529b5ea0fb59275c440fa323cc7c1c672fe80616804f8604731f5ae870
7
+ data.tar.gz: 9802793529d7d68b1814204e2d31213ba25c6a473e64a897e36d08aba79318960d1efeac63fb3c9dba8b9e234765ecaa50606db52548fffe987f5f422466a0fd
data/README.md CHANGED
@@ -3,22 +3,17 @@
3
3
  Easily start up a local NSQ cluster. This is great for testing.
4
4
 
5
5
  ```ruby
6
- # Start a cluster of 3 nsqd's and 2 nsqlookupd's
6
+ # Start a cluster of 3 nsqd's and 2 nsqlookupd's.
7
+ # This will block execution until all components are fully up and running.
7
8
  cluster = NsqCluster.new(nsqd_count: 3, nsqlookupd_count: 2)
8
9
 
9
- # Optionally, block until the cluster is up and running
10
- cluster.block_until_running
11
-
12
- # Stop the 3rd nsqd instance
10
+ # Stop the 3rd nsqd instance and wait for it to come down.
13
11
  cluster.nsqd.last.stop
14
12
 
15
- # Wait until it's stopped
16
- cluster.nsqd.last.block_until_stopped
17
-
18
- # Start it back up again
13
+ # Start it back up again and wait for it to fully start.
19
14
  cluster.nsqd.last.start
20
15
 
21
- # Tear down the whole cluster
16
+ # Tear down the whole cluster.
22
17
  cluster.destroy
23
18
  ```
24
19
 
data/lib/nsq-cluster.rb CHANGED
@@ -38,7 +38,10 @@ class NsqCluster
38
38
 
39
39
  begin
40
40
  # start everything!
41
- all_services.each { |d| d.start }
41
+ all_services.each{|d| d.start(async: true)}
42
+
43
+ # by default, block execution until everything is started
44
+ block_until_running unless opts[:async]
42
45
  rescue Exception => ex
43
46
  # if we hit an error, stop everything that we started
44
47
  destroy
@@ -51,8 +54,7 @@ class NsqCluster
51
54
  (0...count).map do |idx|
52
55
  Nsqlookupd.new(
53
56
  options.merge({
54
- tcp_port: 4160 + idx * 2,
55
- http_port: 4161 + idx * 2
57
+ id: idx
56
58
  }),
57
59
  @verbose
58
60
  )
@@ -64,9 +66,8 @@ class NsqCluster
64
66
  (0...count).map do |idx|
65
67
  Nsqd.new(
66
68
  options.merge({
67
- tcp_port: 4150 + idx * 2,
68
- http_port: 4151 + idx * 2,
69
- nsqlookupd: @nsqlookupd,
69
+ id: idx,
70
+ nsqlookupd: @nsqlookupd
70
71
  }),
71
72
  @verbose
72
73
  )
@@ -19,7 +19,7 @@ class Nsqadmin < ProcessWrapper
19
19
  end
20
20
 
21
21
 
22
- def stop
22
+ def stop(opts = {})
23
23
  Sys::ProcTable.ps.select{|pe| pe.ppid == @pid}.each do |child_pid|
24
24
  Process.kill('TERM', child_pid)
25
25
  end
@@ -6,15 +6,16 @@ class Nsqd < ProcessWrapper
6
6
  include HTTPWrapper
7
7
 
8
8
 
9
- attr_reader :host, :tcp_port, :http_port
9
+ attr_reader :host, :tcp_port, :http_port, :id
10
10
 
11
11
 
12
12
  def initialize(opts = {}, verbose = false)
13
13
  super
14
14
 
15
+ @id = opts.delete(:id) || 0
15
16
  @host = opts.delete(:host) || '127.0.0.1'
16
- @tcp_port = opts.delete(:tcp_port) || 4150
17
- @http_port = opts.delete(:http_port) || 4151
17
+ @tcp_port = opts.delete(:tcp_port) || (4150 + @id * 2)
18
+ @http_port = opts.delete(:http_port) || (4151 + @id * 2)
18
19
  @lookupd = opts.delete(:nsqlookupd) || []
19
20
  @broadcast_address = opts.delete(:broadcast_address) || @host
20
21
 
@@ -43,7 +44,7 @@ class Nsqd < ProcessWrapper
43
44
  %Q(--tcp-address=#{@host}:#{@tcp_port}),
44
45
  %Q(--http-address=#{@host}:#{@http_port}),
45
46
  %Q(--data-path=#{data_path}),
46
- %Q(--worker-id=#{worker_id}),
47
+ %Q(--worker-id=#{id}),
47
48
  %Q(--broadcast-address=#{@broadcast_address})
48
49
  ]
49
50
 
@@ -55,14 +56,9 @@ class Nsqd < ProcessWrapper
55
56
  end
56
57
 
57
58
 
58
- def worker_id
59
- @tcp_port
60
- end
61
-
62
-
63
59
  # find or create a temporary data directory for this instance
64
60
  def data_path
65
- "/tmp/nsqd-#{worker_id}"
61
+ "/tmp/nsqd-#{id}"
66
62
  end
67
63
 
68
64
 
@@ -9,9 +9,10 @@ class Nsqlookupd < ProcessWrapper
9
9
  def initialize(opts = {}, verbose = false)
10
10
  super
11
11
 
12
+ @id = opts.delete(:id) || 0
12
13
  @host = opts.delete(:host) || '127.0.0.1'
13
- @tcp_port = opts.delete(:tcp_port) || 4160
14
- @http_port = opts.delete(:http_port) || 4161
14
+ @tcp_port = opts.delete(:tcp_port) || (4160 + @id * 2)
15
+ @http_port = opts.delete(:http_port) || (4161 + @id * 2)
15
16
  @broadcast_address = opts.delete(:broadcast_address) || @host
16
17
 
17
18
  @extra_args = opts.map do |key, value|
@@ -8,22 +8,24 @@ class ProcessWrapper
8
8
  end
9
9
 
10
10
 
11
- def start
11
+ def start(opts = {})
12
12
  raise "#{command} is already running" if running? || another_instance_is_running?
13
13
  @pid = spawn(command, *args, [:out, :err] => output)
14
+ block_until_running unless opts[:async]
14
15
  end
15
16
 
16
17
 
17
- def stop
18
+ def stop(opts = {})
18
19
  raise "#{command} is not running" unless running?
19
20
  Process.kill('TERM', @pid)
20
21
  Process.waitpid(@pid)
21
22
  @pid = nil
23
+ block_until_stopped unless opts[:async]
22
24
  end
23
25
 
24
26
 
25
27
  def destroy
26
- stop if running?
28
+ stop(async: true) if running?
27
29
  end
28
30
 
29
31
 
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.3.0
4
+ version: 1.0.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-29 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sys-proctable