retryable 2.0.1 → 2.0.2

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: e02743f5a92c56de8d631d1ce21a2bc1b18abacf
4
- data.tar.gz: 236dafbf366171b840d64a1317ad14becf56c099
3
+ metadata.gz: b8f678cc21a51e9421bbef9213728686216611e1
4
+ data.tar.gz: 88c5cfb49b9b9e91db47aa937283082b20053c98
5
5
  SHA512:
6
- metadata.gz: a9cbd76de408e65f6b6238de7082c017a2a05278f5f01c38cacc8088929f08ae4266c1c711a8290fb7255d87120fe83295d63cd7758f66ae7332b0cb35ec490a
7
- data.tar.gz: 89fe460024058360678c483b41e75bc75442446c4698df5623bad47e09b0b5321b5370441595940ce8ef9446c772ed1f37523f55f5014c9a493efdd0da744bd0
6
+ metadata.gz: 3aa5569b58419a57c8ce537ed9fe621ced5551f1685671765092800a3b57d6d3e0327b9389dd2277f716833b432c933ff80fbc81f18195760d4ed47a701564f0
7
+ data.tar.gz: f798b44022d4bc1607d890b2b804b4f5837ae6e1b95311912d8791684bde2da4aa429f70348463321078e7f253586ab7dbde03aa3c2dc0f909574e210bd193d3
data/README.md CHANGED
@@ -9,7 +9,7 @@ Description
9
9
  Runs a code block, and retries it when an exception occurs. It's great when
10
10
  working with flakey webservices (for example).
11
11
 
12
- It's configured using four optional parameters `:tries`, `:on`, `:sleep`, `:matching`, `:ensure`, `:exception_cb` and
12
+ It's configured using five optional parameters `:tries`, `:on`, `:sleep`, `:matching`, `:ensure`, `:exception_cb`, `:not` and
13
13
  runs the passed block. Should an exception occur, it'll retry for (n-1) times.
14
14
 
15
15
  Should the number of retries be reached without success, the last exception
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  ## Defaults
58
58
 
59
- :tries => 2, :on => StandardError, :sleep => 1, :matching => /.*/, :ensure => Proc.new { }, :exception_cb => Proc.new { }
59
+ :tries => 2, :on => StandardError, :sleep => 1, :matching => /.*/, :ensure => Proc.new { }, :exception_cb => Proc.new { }, :not => []
60
60
 
61
61
  Retryable also could be configured globally to change those defaults:
62
62
 
@@ -68,6 +68,7 @@ Retryable.configure do |config|
68
68
  config.on = StandardError
69
69
  config.sleep = 1
70
70
  config.tries = 2
71
+ config.not = []
71
72
  end
72
73
  ```
73
74
 
@@ -130,6 +131,20 @@ Retryable.enabled?
130
131
  => false
131
132
  ```
132
133
 
134
+ Specify exceptions where a retry should NOT be performed
135
+ --------
136
+ No more tries will be made if an exception listed in `:not` is raised.
137
+ Takes precedence over `:on`.
138
+
139
+ ```
140
+ class MyError < StandardError; end
141
+
142
+ Retryable.retryable(:tries => 5, :on => [StandardError], :not => [MyError]) do
143
+ raise MyError "No retries!"
144
+ end
145
+
146
+ ```
147
+
133
148
  Supported Ruby Versions
134
149
  -------
135
150
 
@@ -17,6 +17,7 @@ module Retryable
17
17
  # config.on = StandardError
18
18
  # config.sleep = 1
19
19
  # config.tries = 2
20
+ # config.not = []
20
21
  # end
21
22
  def configure
22
23
  yield(configuration)
@@ -47,7 +48,8 @@ module Retryable
47
48
  :on => self.configuration.on,
48
49
  :matching => self.configuration.matching,
49
50
  :ensure => self.configuration.ensure,
50
- :exception_cb => self.configuration.exception_cb
51
+ :exception_cb => self.configuration.exception_cb,
52
+ :not => self.configuration.not
51
53
  }
52
54
 
53
55
  check_for_invalid_options(options, opts)
@@ -55,12 +57,16 @@ module Retryable
55
57
 
56
58
  return if opts[:tries] == 0
57
59
 
58
- on_exception, tries = [ opts[:on] ].flatten, opts[:tries]
60
+ on_exception = [ opts[:on] ].flatten
61
+ not_exception = [ opts[:not] ].flatten
62
+ tries = opts[:tries]
59
63
  retries = 0
60
64
  retry_exception = nil
61
65
 
62
66
  begin
63
67
  return yield retries, retry_exception
68
+ rescue *not_exception
69
+ raise
64
70
  rescue *on_exception => exception
65
71
  raise unless configuration.enabled?
66
72
  raise unless exception.message =~ opts[:matching]
@@ -69,6 +75,8 @@ module Retryable
69
75
  # Interrupt Exception could be raised while sleeping
70
76
  begin
71
77
  Kernel.sleep opts[:sleep].respond_to?(:call) ? opts[:sleep].call(retries) : opts[:sleep]
78
+ rescue *not_exception
79
+ raise
72
80
  rescue *on_exception
73
81
  end
74
82
 
@@ -90,4 +98,3 @@ module Retryable
90
98
  end
91
99
  end
92
100
  end
93
-
@@ -7,7 +7,8 @@ module Retryable
7
7
  :matching,
8
8
  :on,
9
9
  :sleep,
10
- :tries
10
+ :tries,
11
+ :not
11
12
  ].freeze
12
13
 
13
14
  attr_accessor :ensure
@@ -16,6 +17,7 @@ module Retryable
16
17
  attr_accessor :on
17
18
  attr_accessor :sleep
18
19
  attr_accessor :tries
20
+ attr_accessor :not
19
21
 
20
22
  attr_accessor :enabled
21
23
 
@@ -28,6 +30,7 @@ module Retryable
28
30
  @on = StandardError
29
31
  @sleep = 1
30
32
  @tries = 2
33
+ @not = []
31
34
 
32
35
  @enabled = true
33
36
  end
@@ -2,7 +2,7 @@ module Retryable
2
2
  class Version
3
3
  MAJOR = 2 unless defined? Retryable::Version::MAJOR
4
4
  MINOR = 0 unless defined? Retryable::Version::MINOR
5
- PATCH = 1 unless defined? Retryable::Version::PATCH
5
+ PATCH = 2 unless defined? Retryable::Version::PATCH
6
6
 
7
7
  class << self
8
8
 
@@ -115,4 +115,18 @@ RSpec.describe 'Retryable.retryable' do
115
115
 
116
116
  expect(@raised).to eq("this is fun!")
117
117
  end
118
+
119
+ it 'does not retry on :not exception' do
120
+ expect do
121
+ count_retryable(:not => RuntimeError ) { |tries, ex| raise RuntimeError if tries < 1 }
122
+ end.to raise_error RuntimeError
123
+ expect(@try_count).to eq(1)
124
+ end
125
+
126
+ it 'gives precidence for :not over :on' do
127
+ expect do
128
+ count_retryable(:sleep => 0, :tries => 3, :on => StandardError, :not => IndexError ) { |tries, ex| raise tries >= 1 ? IndexError : StandardError }
129
+ end.to raise_error IndexError
130
+ expect(@try_count).to eq(2)
131
+ end
118
132
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retryable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Fedyashev
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-30 00:00:00.000000000 Z
13
+ date: 2015-08-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: 1.3.6
63
63
  requirements: []
64
64
  rubyforge_project:
65
- rubygems_version: 2.4.5
65
+ rubygems_version: 2.4.6
66
66
  signing_key:
67
67
  specification_version: 4
68
68
  summary: Retryable#retryable, allow for retrying of code blocks.