fastly_nsq 1.2.0 → 1.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: 553d58c7ebd2909c851799e269e6ad6d4ef1ad6f
4
- data.tar.gz: b99a102f8a6659a3c325c1ae79a9e5c03876745c
3
+ metadata.gz: e9571195fbffa3a39f6492fc49347bd85c1bfaac
4
+ data.tar.gz: 90ca9fe5c3e90bcf601d6c6eace43dfa8ebd0b05
5
5
  SHA512:
6
- metadata.gz: cecf8dc69439bdbe7e05cae3fbbce5862ee42fdb947f177e4480bb464f9b7fd925ec099151164833d24ddf3dba51dffa06b270375422a7e7c9dc7f8c104a5d7c
7
- data.tar.gz: 92f7c3759578cec172c5ef6851cf9993cf1b5ee33b15baa338918044ca0e3d05f867c2641f66f6946e4ddebdb8f9373fddec7fb3afc39d9eddd50aa56b334e0b
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, :preprocessor
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)
@@ -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
  )
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastlyNsq
4
- VERSION = '1.2.0'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -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
- it 'can be passed to the consumer' do
20
- listener = described_class.new topic: topic,
21
- processor: processor,
22
- channel: channel,
23
- max_attempts: 5
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(5)
30
+ expect(nsq_connection.instance_variable_get(:@max_attempts)).to eq(FastlyNsq.max_attempts)
27
31
  end
28
32
  end
29
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly_nsq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy O'Neil