fastly_nsq 1.2.0 → 1.3.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 +4 -4
- data/lib/fastly_nsq.rb +3 -1
- data/lib/fastly_nsq/consumer.rb +4 -1
- data/lib/fastly_nsq/listener.rb +5 -2
- data/lib/fastly_nsq/version.rb +1 -1
- data/spec/listener_spec.rb +11 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9571195fbffa3a39f6492fc49347bd85c1bfaac
|
4
|
+
data.tar.gz: 90ca9fe5c3e90bcf601d6c6eace43dfa8ebd0b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 083ea4782ca2fbae00c977a8df145eb2aedceeab334e465fb8d76313582121bb2ee0aab174b96a12f64d012866e5be392ab67507d23428a5da30952cc3c7577a
|
7
|
+
data.tar.gz: 07a6dcdeb0ae6cd14750a3b9556beaac9937452ca329f895315d1915da2ff1f26638cb3e5cd67cb97e3a22b376506de7cd38f788449ae20ba2c96f9ea136e659
|
data/lib/fastly_nsq.rb
CHANGED
@@ -12,7 +12,9 @@ module FastlyNsq
|
|
12
12
|
ConnectionFailed = Class.new(StandardError)
|
13
13
|
|
14
14
|
class << self
|
15
|
-
attr_accessor :channel
|
15
|
+
attr_accessor :channel
|
16
|
+
attr_accessor :preprocessor
|
17
|
+
attr_accessor :max_attempts
|
16
18
|
attr_writer :logger
|
17
19
|
|
18
20
|
def listen(topic, processor, **options)
|
data/lib/fastly_nsq/consumer.rb
CHANGED
@@ -6,14 +6,16 @@ class FastlyNsq::Consumer
|
|
6
6
|
DEFAULT_CONNECTION_TIMEOUT = 5 # seconds
|
7
7
|
|
8
8
|
attr_reader :channel, :topic, :connection, :connect_timeout
|
9
|
+
attr_reader :max_attempts
|
9
10
|
|
10
11
|
def_delegators :connection, :size, :terminate, :connected?, :pop, :pop_without_blocking
|
11
12
|
|
12
|
-
def initialize(topic:, channel:, queue: nil, tls_options: nil, connect_timeout: DEFAULT_CONNECTION_TIMEOUT, **options)
|
13
|
+
def initialize(topic:, channel:, queue: nil, tls_options: nil, connect_timeout: DEFAULT_CONNECTION_TIMEOUT, max_attempts: FastlyNsq.max_attempts, **options)
|
13
14
|
@topic = topic
|
14
15
|
@channel = channel
|
15
16
|
@tls_options = FastlyNsq::TlsOptions.as_hash(tls_options)
|
16
17
|
@connect_timeout = connect_timeout
|
18
|
+
@max_attempts = max_attempts
|
17
19
|
|
18
20
|
@connection = connect(queue, **options)
|
19
21
|
end
|
@@ -33,6 +35,7 @@ class FastlyNsq::Consumer
|
|
33
35
|
topic: topic,
|
34
36
|
channel: channel,
|
35
37
|
queue: queue,
|
38
|
+
max_attempts: max_attempts,
|
36
39
|
**options,
|
37
40
|
}.merge(tls_options),
|
38
41
|
)
|
data/lib/fastly_nsq/listener.rb
CHANGED
@@ -9,25 +9,28 @@ class FastlyNsq::Listener
|
|
9
9
|
def_delegators :consumer, :connected?
|
10
10
|
|
11
11
|
attr_reader :preprocessor, :topic, :processor, :priority, :channel, :logger, :consumer
|
12
|
+
attr_reader :max_attempts
|
12
13
|
|
13
14
|
def initialize(topic:, processor:, preprocessor: FastlyNsq.preprocessor, channel: FastlyNsq.channel, consumer: nil,
|
14
15
|
logger: FastlyNsq.logger, priority: DEFAULT_PRIORITY, connect_timeout: DEFAULT_CONNECTION_TIMEOUT,
|
15
|
-
**consumer_options)
|
16
|
+
max_attempts: FastlyNsq.max_attempts, **consumer_options)
|
16
17
|
|
17
18
|
raise ArgumentError, "processor #{processor.inspect} does not respond to #call" unless processor.respond_to?(:call)
|
18
19
|
raise ArgumentError, "priority #{priority.inspect} must be a Integer" unless priority.is_a?(Integer)
|
19
20
|
|
20
21
|
@channel = channel
|
21
22
|
@logger = logger
|
23
|
+
@max_attempts = max_attempts
|
22
24
|
@preprocessor = preprocessor
|
25
|
+
@priority = priority
|
23
26
|
@processor = processor
|
24
27
|
@topic = topic
|
25
|
-
@priority = priority
|
26
28
|
|
27
29
|
@consumer = consumer || FastlyNsq::Consumer.new(topic: topic,
|
28
30
|
connect_timeout: connect_timeout,
|
29
31
|
channel: channel,
|
30
32
|
queue: FastlyNsq::Feeder.new(self, priority),
|
33
|
+
max_attempts: max_attempts,
|
31
34
|
**consumer_options)
|
32
35
|
|
33
36
|
FastlyNsq.manager.add_listener(self)
|
data/lib/fastly_nsq/version.rb
CHANGED
data/spec/listener_spec.rb
CHANGED
@@ -15,15 +15,19 @@ RSpec.describe FastlyNsq::Listener do
|
|
15
15
|
subject { described_class.new(topic: topic, channel: channel, processor: processor) }
|
16
16
|
|
17
17
|
describe '#initialize' do
|
18
|
-
describe 'max_attempts' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
describe 'with FastlyNsq.max_attempts set' do
|
19
|
+
let!(:default_max_attempts) { FastlyNsq.max_attempts }
|
20
|
+
before { FastlyNsq.max_attempts = 19 }
|
21
|
+
after { FastlyNsq.max_attempts = default_max_attempts }
|
22
|
+
|
23
|
+
it 'defaults to FastlyNsq.max_attempts' do
|
24
|
+
listener = described_class.new(topic: topic, processor: processor, channel: channel)
|
25
|
+
expect(listener.max_attempts).to eq(FastlyNsq.max_attempts)
|
26
|
+
|
24
27
|
expect { listener }.to eventually(be_connected).within(5)
|
28
|
+
|
25
29
|
nsq_connection = listener.consumer.connection.connections.values.first # whoa
|
26
|
-
expect(nsq_connection.instance_variable_get(:@max_attempts)).to eq(
|
30
|
+
expect(nsq_connection.instance_variable_get(:@max_attempts)).to eq(FastlyNsq.max_attempts)
|
27
31
|
end
|
28
32
|
end
|
29
33
|
|