retryable 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +4 -0
- data/README.md +6 -1
- data/lib/retryable.rb +18 -3
- data/lib/retryable/version.rb +1 -1
- data/spec/retryable_spec.rb +17 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 441e4e21d1cbf851bc4ce28f99774b1b0e0058920f401926259b08d311fc6f4d
|
4
|
+
data.tar.gz: 0c7b6ec7ac61587f68c4186405e00b4f2021558520b692ebe6b013503bccf97d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ff21470b65d4037e2cc88b00f8404d72327cb3891fde218794242b76b7e7d90de8c1e6cb88756effe70886a84d515efb0c08ac4f491962b85f2689423e44d87
|
7
|
+
data.tar.gz: bcc68f82b11fae2876ae81730c5d953291428b8524dc68e221961666375216004ed447af9ad3eac1b1f7342eb110ab1597320c3a0469afcad4e276383262958d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Retryable 3.0.1 ##
|
2
|
+
|
3
|
+
* :matching param from now on could be called in form of array with multiple matching conditions. This version is backwards compatible with 3.0.0
|
4
|
+
|
1
5
|
## Retryable 3.0.0 ##
|
2
6
|
NOTE: this version is backwards compatible with 2.0.4 version unless you're running it against Ruby 1.8 version.
|
3
7
|
|
data/README.md
CHANGED
@@ -91,7 +91,7 @@ end
|
|
91
91
|
exception_cb: proc { },
|
92
92
|
not: [],
|
93
93
|
sleep_method: lambda { |n| Kernel.sleep(n) },
|
94
|
-
contexts
|
94
|
+
contexts: {}
|
95
95
|
|
96
96
|
Retryable also could be configured globally to change those defaults:
|
97
97
|
|
@@ -128,6 +128,11 @@ You can also retry based on the exception message:
|
|
128
128
|
Retryable.retryable(matching: /IO timeout/) do |retries, exception|
|
129
129
|
raise "oops IO timeout!" if retries == 0
|
130
130
|
end
|
131
|
+
|
132
|
+
#matching param supports array format as well:
|
133
|
+
Retryable.retryable(matching: [/IO timeout/, "IO tymeout"]) do |retries, exception|
|
134
|
+
raise "oops IO timeout!" if retries == 0
|
135
|
+
end
|
131
136
|
```
|
132
137
|
|
133
138
|
Block Parameters
|
data/lib/retryable.rb
CHANGED
@@ -60,8 +60,10 @@ module Retryable
|
|
60
60
|
|
61
61
|
return if opts[:tries] == 0
|
62
62
|
|
63
|
-
on_exception = [opts[:on]]
|
64
|
-
not_exception = [opts[:not]]
|
63
|
+
on_exception = opts[:on].is_a?(Array) ? opts[:on] : [opts[:on]]
|
64
|
+
not_exception = opts[:not].is_a?(Array) ? opts[:not] : [opts[:not]]
|
65
|
+
|
66
|
+
matching = [opts[:matching]].flatten
|
65
67
|
tries = opts[:tries]
|
66
68
|
retries = 0
|
67
69
|
retry_exception = nil
|
@@ -72,7 +74,7 @@ module Retryable
|
|
72
74
|
raise
|
73
75
|
rescue *on_exception => exception
|
74
76
|
raise unless configuration.enabled?
|
75
|
-
raise unless exception.message
|
77
|
+
raise unless matches?(exception.message, matching)
|
76
78
|
raise if tries != :infinite && retries + 1 >= tries
|
77
79
|
|
78
80
|
# Interrupt Exception could be raised while sleeping
|
@@ -100,5 +102,18 @@ module Retryable
|
|
100
102
|
return if invalid_options.empty?
|
101
103
|
raise ArgumentError, "[Retryable] Invalid options: #{invalid_options.join(', ')}"
|
102
104
|
end
|
105
|
+
|
106
|
+
def matches?(message, candidates)
|
107
|
+
candidates.any? do |candidate|
|
108
|
+
case candidate
|
109
|
+
when String
|
110
|
+
message.include?(candidate)
|
111
|
+
when Regexp
|
112
|
+
message =~ candidate
|
113
|
+
else
|
114
|
+
raise ArgumentError, ":matches must be a string or regex"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
103
118
|
end
|
104
119
|
end
|
data/lib/retryable/version.rb
CHANGED
data/spec/retryable_spec.rb
CHANGED
@@ -57,6 +57,13 @@ RSpec.describe Retryable do
|
|
57
57
|
expect(counter.count).to eq(2)
|
58
58
|
end
|
59
59
|
|
60
|
+
it 'does not retry on :not exception which is covered by Array' do
|
61
|
+
expect do
|
62
|
+
counter(not: [RuntimeError, IndexError]) { |tries| raise RuntimeError if tries < 1 }
|
63
|
+
end.to raise_error RuntimeError
|
64
|
+
expect(counter.count).to eq(1)
|
65
|
+
end
|
66
|
+
|
60
67
|
it 'does not try on unexpected exception' do
|
61
68
|
allow(Kernel).to receive(:sleep)
|
62
69
|
expect do
|
@@ -117,6 +124,16 @@ RSpec.describe Retryable do
|
|
117
124
|
expect(counter.count).to eq(1)
|
118
125
|
end
|
119
126
|
|
127
|
+
it 'catches an exception in the list of matches' do
|
128
|
+
expect(Kernel).to receive(:sleep).once.with(1)
|
129
|
+
counter(matching: [/IO timeout/, "IO tymeout"]) { |c, _e| raise 'yo, IO timeout!' if c == 0 }
|
130
|
+
expect(counter.count).to eq(2)
|
131
|
+
|
132
|
+
expect(Kernel).to receive(:sleep).once.with(1)
|
133
|
+
counter(matching: [/IO timeout/, "IO tymeout"]) { |c, _e| raise 'yo, IO tymeout!' if c == 0 }
|
134
|
+
expect(counter.count).to eq(4)
|
135
|
+
end
|
136
|
+
|
120
137
|
it 'does not allow invalid options' do
|
121
138
|
expect do
|
122
139
|
described_class.retryable(bad_option: 2) { raise 'this is bad' }
|
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: 3.0.
|
4
|
+
version: 3.0.1
|
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: 2018-
|
13
|
+
date: 2018-04-11 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: 1.3.6
|
69
69
|
requirements: []
|
70
70
|
rubyforge_project:
|
71
|
-
rubygems_version: 2.
|
71
|
+
rubygems_version: 2.7.3
|
72
72
|
signing_key:
|
73
73
|
specification_version: 4
|
74
74
|
summary: Retrying code blocks in Ruby
|