shoryuken 3.1.10 → 3.1.11

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: 4dda2c81b7db286ab0286fc53d6f809a94036827
4
- data.tar.gz: d95cc4ea313c9df67a3fa91147874f5361ddbdbf
3
+ metadata.gz: 790d69004ca82f39b30f5c8bc94a22666c5d4dae
4
+ data.tar.gz: 64d8533b1e113cf735d235b39390096e4fe66501
5
5
  SHA512:
6
- metadata.gz: cd5ce448af5d501a27b15419617dec8c38d03f7134898f617b8a9fe23c291917186f00918c962f11cf45dca19c9ff6d87c7f85c805f265edce3dc0b6dfa686e9
7
- data.tar.gz: 33baff2079043bea32abf2d372035301e4ceadf65b9156caa3140233a643578113df2790cd2211e92b0502164388fc99087ece4f8ebebf6e202a840accd4deee
6
+ metadata.gz: 6fb9d015a01aef9d4f0288872e52ec05302f18d74594080b8c8220669fb5ccf822fff031bd36ddd94094371f471c6af95b253217ef3ee5a5ebc76979f13b1289
7
+ data.tar.gz: 0a00108dbbbf108a98f2d571d6635f8cf49c7230608b3d9c776a770f6c3cc61b6ccdee9a162c05d7dfa41e7921ef1756cfd546fe285bfd0ccb8e874fdb0699b8
@@ -1,3 +1,8 @@
1
+ ## [v3.1.11] - 2017-09-02
2
+
3
+ - Auto retry (up to 3 times) fetch errors
4
+ - [#429](https://github.com/phstc/shoryuken/pull/429)
5
+
1
6
  ## [v3.1.10] - 2017-09-02
2
7
 
3
8
  - Make Shoryuken compatible with AWS SDK 3 and 2
@@ -9,20 +9,41 @@ module Shoryuken
9
9
  end
10
10
 
11
11
  def fetch(queue, limit)
12
- started_at = Time.now
12
+ fetch_with_auto_retry(3) do
13
+ started_at = Time.now
13
14
 
14
- logger.debug { "Looking for new messages in #{queue}" }
15
+ logger.debug { "Looking for new messages in #{queue}" }
15
16
 
16
- sqs_msgs = Array(receive_messages(queue, [FETCH_LIMIT, limit].min))
17
+ sqs_msgs = Array(receive_messages(queue, [FETCH_LIMIT, limit].min))
17
18
 
18
- logger.info { "Found #{sqs_msgs.size} messages for #{queue.name}" } unless sqs_msgs.empty?
19
- logger.debug { "Fetcher for #{queue} completed in #{elapsed(started_at)} ms" }
19
+ logger.info { "Found #{sqs_msgs.size} messages for #{queue.name}" } unless sqs_msgs.empty?
20
+ logger.debug { "Fetcher for #{queue} completed in #{elapsed(started_at)} ms" }
20
21
 
21
- sqs_msgs
22
+ sqs_msgs
23
+ end
22
24
  end
23
25
 
24
26
  private
25
27
 
28
+ def fetch_with_auto_retry(max_attempts, &block)
29
+ attempts = 0
30
+
31
+ begin
32
+ yield
33
+ rescue => ex
34
+ # Tries to auto retry connectivity errors
35
+ raise if attempts >= max_attempts
36
+
37
+ attempts += 1
38
+
39
+ logger.debug { "Retrying fetch attempt #{attempts} for #{ex.message}" }
40
+
41
+ sleep((1..5).to_a.sample)
42
+
43
+ retry
44
+ end
45
+ end
46
+
26
47
  def receive_messages(queue, limit)
27
48
  options = receive_options(queue)
28
49
 
@@ -12,6 +12,7 @@ module Shoryuken
12
12
  @max_processors = concurrency
13
13
  @busy_processors = Concurrent::AtomicFixnum.new(0)
14
14
  @executor = executor
15
+ @running = Concurrent::AtomicBoolean.new(true)
15
16
  end
16
17
 
17
18
  def start
@@ -21,7 +22,7 @@ module Shoryuken
21
22
  private
22
23
 
23
24
  def running?
24
- @executor.running?
25
+ @running.true? && @executor.running?
25
26
  end
26
27
 
27
28
  def dispatch_loop
@@ -104,6 +105,8 @@ module Shoryuken
104
105
  logger.error { ex.backtrace.join("\n") } unless ex.backtrace.nil?
105
106
 
106
107
  Process.kill('USR1', Process.pid)
108
+
109
+ @running.make_false
107
110
  end
108
111
  end
109
112
  end
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '3.1.10'.freeze
2
+ VERSION = '3.1.11'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoryuken
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.10
4
+ version: 3.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero