nsq-ruby 1.2.0 → 1.2.1

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: cbfb90bdb3cd20d66a806966a6b3eda69128da2d
4
- data.tar.gz: 34768fbb3f8146dd971c24cf14e8f8a6eb33dc5a
3
+ metadata.gz: 09966bb130fd77c7eb78c70c654afb4b2bd2246c
4
+ data.tar.gz: a900ade8f7497c4fcc738cd82900f90da7bb0172
5
5
  SHA512:
6
- metadata.gz: baffdc2899b758231cd9cece73b598114d826bd18ca4bc909873f353884dd0ca15f5c6f612ad6dd5b6cf032a283c9f080df992cd9d264a28c4d6a5474bd4d89a
7
- data.tar.gz: 16eec84732c35cca1adafa34b4ecd6cb08ced46f534977fd801552d5ca3f28e82853ce7427e100ad5a180693eeac3f1beac04c996fef87a597c10fdd120f15b3
6
+ metadata.gz: 9f7ce184b29b4eb00b46826a0ae3bbaa408cef197c89f6c074d4379c6e8e5623f38bcea1a587550c14734fdd19bb133f186ed910e85c5255c11d659ff70b4176
7
+ data.tar.gz: 2a0360c7b8b90e9099ae1e3dc1ad96de0ead23b3732ccafdc02e851fcab4af9a087c44f43f96d1d5d5ab34c2da45c086616bc17e19cb1bf3b5a1bbf029cdcb10
data/lib/nsq.rb CHANGED
@@ -2,6 +2,8 @@ require_relative 'version'
2
2
 
3
3
  require_relative 'nsq/logger'
4
4
 
5
+ require_relative 'nsq/exceptions'
6
+
5
7
  require_relative 'nsq/frames/frame'
6
8
  require_relative 'nsq/frames/error'
7
9
  require_relative 'nsq/frames/response'
@@ -36,8 +36,14 @@ module Nsq
36
36
  @discovery = Discovery.new(opts[:nsqlookupds])
37
37
 
38
38
  loop do
39
- nsqds = nsqds_from_lookupd(opts[:topic])
40
- drop_and_add_connections(nsqds)
39
+ begin
40
+ nsqds = nsqds_from_lookupd(opts[:topic])
41
+ drop_and_add_connections(nsqds)
42
+ rescue DiscoveryException
43
+ # We can't connect to any nsqlookupds. That's okay, we'll just
44
+ # leave our current nsqd connections alone and try again later.
45
+ warn 'Could not connect to any nsqlookupd instances in discovery loop'
46
+ end
41
47
  sleep opts[:interval]
42
48
  end
43
49
 
@@ -393,7 +393,8 @@ module Nsq
393
393
  def server_needs_rdy_re_ups?
394
394
  # versions less than 0.3.0 need RDY re-ups
395
395
  # see: https://github.com/bitly/nsq/blob/master/ChangeLog.md#030---2014-11-18
396
- @server_version.split('.')[0].to_i == 0 && @server_version.split('.')[1].to_i <= 2
396
+ major, minor, patch = @server_version.split('.').map(&:to_i)
397
+ major == 0 && minor <= 2
397
398
  end
398
399
 
399
400
 
data/lib/nsq/discovery.rb CHANGED
@@ -21,10 +21,12 @@ module Nsq
21
21
  # discovery.nsqds
22
22
  # #=> ['127.0.0.1:4150', '127.0.0.1:4152']
23
23
  #
24
+ # If all nsqlookupd's are unreachable, raises Nsq::DiscoveryException
25
+ #
24
26
  def nsqds
25
- @lookupds.map do |lookupd|
27
+ gather_nsqds_from_all_lookupds do |lookupd|
26
28
  get_nsqds(lookupd)
27
- end.flatten.uniq
29
+ end
28
30
  end
29
31
 
30
32
  # Returns an array of nsqds instances that have messages for
@@ -35,14 +37,32 @@ module Nsq
35
37
  # discovery.nsqds_for_topic('a-topic')
36
38
  # #=> ['127.0.0.1:4150', '127.0.0.1:4152']
37
39
  #
40
+ # If all nsqlookupd's are unreachable, raises Nsq::DiscoveryException
41
+ #
38
42
  def nsqds_for_topic(topic)
39
- @lookupds.map do |lookupd|
43
+ gather_nsqds_from_all_lookupds do |lookupd|
40
44
  get_nsqds(lookupd, topic)
41
- end.flatten.uniq
45
+ end
42
46
  end
43
47
 
48
+
44
49
  private
45
50
 
51
+ def gather_nsqds_from_all_lookupds
52
+ nsqd_list = @lookupds.map do |lookupd|
53
+ yield(lookupd)
54
+ end.flatten
55
+
56
+ # All nsqlookupds were unreachable, raise an error!
57
+ if nsqd_list.length > 0 && nsqd_list.all? { |nsqd| nsqd.nil? }
58
+ raise DiscoveryException
59
+ end
60
+
61
+ nsqd_list.compact.uniq
62
+ end
63
+
64
+ # Returns an array of nsqd addresses
65
+ # If there's an error, return nil
46
66
  def get_nsqds(lookupd, topic = nil)
47
67
  uri_scheme = 'http://' unless lookupd.match(%r(https?://))
48
68
  uri = URI.parse("#{uri_scheme}#{lookupd}")
@@ -68,7 +88,7 @@ module Nsq
68
88
  end
69
89
  rescue Exception => e
70
90
  error "Error during discovery for #{lookupd}: #{e}"
71
- []
91
+ nil
72
92
  end
73
93
  end
74
94
 
@@ -0,0 +1,5 @@
1
+ module Nsq
2
+ # Raised when nsqlookupd discovery fails
3
+ class DiscoveryException < Exception; end
4
+ end
5
+
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module Nsq
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  BUILD = nil
7
7
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsq-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wistia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-02 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,7 @@ files:
81
81
  - lib/nsq/connection.rb
82
82
  - lib/nsq/consumer.rb
83
83
  - lib/nsq/discovery.rb
84
+ - lib/nsq/exceptions.rb
84
85
  - lib/nsq/frames/error.rb
85
86
  - lib/nsq/frames/frame.rb
86
87
  - lib/nsq/frames/message.rb