fastly_nsq 1.3.0 → 1.4.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: e9571195fbffa3a39f6492fc49347bd85c1bfaac
4
- data.tar.gz: 90ca9fe5c3e90bcf601d6c6eace43dfa8ebd0b05
3
+ metadata.gz: 3c2224ce762e2487411032220c774087ec93f288
4
+ data.tar.gz: c6b22724957b8d1cc9233f07c89a5b3ff0cd765e
5
5
  SHA512:
6
- metadata.gz: 083ea4782ca2fbae00c977a8df145eb2aedceeab334e465fb8d76313582121bb2ee0aab174b96a12f64d012866e5be392ab67507d23428a5da30952cc3c7577a
7
- data.tar.gz: 07a6dcdeb0ae6cd14750a3b9556beaac9937452ca329f895315d1915da2ff1f26638cb3e5cd67cb97e3a22b376506de7cd38f788449ae20ba2c96f9ea136e659
6
+ metadata.gz: 426790e527f752f503651e7c34f979eeecbe8908ae1adad34d9ce9d087c7b0d246859b7fa3b7067b22abdae2b4c3f47704f31c015d33b466492e5bca0e7ad16d
7
+ data.tar.gz: 6cff0c873d115bf3042f665f7c9ae6ba136f86ca5ec7dd305f1e32bf7e90ffff4e6adbded480ef4a13ba47e9e62ec9a1ae5c23e7011f6a8661131c4d81aa1849
@@ -34,10 +34,17 @@ class FastlyNsq::Message
34
34
  nsq_message.finish
35
35
  end
36
36
 
37
- def requeue(*args)
37
+ def requeue(timeout = nil)
38
38
  return managed if managed
39
+ timeout ||= requeue_period
39
40
 
40
41
  @managed = :requeued
41
- nsq_message.requeue(*args)
42
+ nsq_message.requeue(timeout)
43
+ end
44
+
45
+ private
46
+
47
+ def requeue_period
48
+ ((attempts**4) + 45 + (rand(60) * (attempts + 1))) * 1_000
42
49
  end
43
50
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FastlyNsq
4
- VERSION = '1.3.0'
4
+ VERSION = '1.4.0'
5
5
  end
data/spec/message_spec.rb CHANGED
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
  require 'json'
5
5
 
6
6
  RSpec.describe FastlyNsq::Message do
7
- let(:nsq_message) { double 'Nsq::Message', body: json_body, attempts: nil, finish: nil, requeue: nil, touch: nil, timestamp: nil }
7
+ let(:nsq_message) { double 'Nsq::Message', body: json_body, attempts: 1, finish: nil, requeue: nil, touch: nil, timestamp: nil }
8
8
  let(:body) { { 'data' => 'goes here', 'other_field' => 'is over here', 'meta' => 'meta stuff' } }
9
9
  let(:json_body) { body.to_json }
10
10
  subject { FastlyNsq::Message.new nsq_message }
@@ -57,4 +57,16 @@ RSpec.describe FastlyNsq::Message do
57
57
 
58
58
  expect(subject.managed).to eq(:finished)
59
59
  end
60
+
61
+ it 'uses the passed timeout for the requeue timeout' do
62
+ expect(nsq_message).to receive(:requeue).with(1000)
63
+
64
+ subject.requeue(1000)
65
+ end
66
+
67
+ it 'uses exponential backoff for timeout if none is given' do
68
+ expect(nsq_message).to receive(:requeue).with(46_000..166_000)
69
+
70
+ subject.requeue
71
+ end
60
72
  end
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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy O'Neil
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2018-04-11 00:00:00.000000000 Z
16
+ date: 2018-04-12 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: awesome_print
@@ -239,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
239
  version: '0'
240
240
  requirements: []
241
241
  rubyforge_project:
242
- rubygems_version: 2.5.1
242
+ rubygems_version: 2.6.14
243
243
  signing_key:
244
244
  specification_version: 4
245
245
  summary: Fastly NSQ Adapter