retriable 2.0.0.beta4 → 2.0.0.beta5

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: 6fb94b8f9e411a4f0939d03f213928e28e002375
4
- data.tar.gz: 703fe21cb7abce08770c7cd5d308099233e8c614
3
+ metadata.gz: a7f89877bb9506abc02a59892b97c55a0f995b38
4
+ data.tar.gz: 7b9e325e86386e6e0e739bb4a51df12882327c1b
5
5
  SHA512:
6
- metadata.gz: d5ed763d75076b92d366854009dd0a0a2df4eeafa184a664c13ba3a01d74968274bff2a61d9a66d201d3c0ad3d913c6e4caf4c75761ba74de447f6aa9eed3d86
7
- data.tar.gz: 06b33e84de325d990cf32790460dfc30dc5eb765db574c344fa64762463ad668ec47d23db41646f748fdb8d658fd3feff069cfac0f748c7ddf238a84479a188b
6
+ metadata.gz: 4fc3260da9272d6fe2a8b29c939ea661e49cb45d28b7a082021a44d6823c96d1612860d6a8cdfe5acc0973c0bdbbeeaa55869f0831999396826b2653c47a29c2
7
+ data.tar.gz: 11113a95d8b63b1bed523f0fd98755dd9b4a176435b40a3cbf877d5eabd136e30aec8eba5ee9b3369d8c1af3311f8883910f7965d19747b077e3dbf9ab867b50
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.0.0.beta5
2
+ * Change :max_tries back to :tries.
3
+
1
4
  ## 2.0.0.beta4
2
5
  * Change #retry back to #retriable. Didn't like the idea of defining a method that is also a reserved word.
3
6
  * Add ability for `:on` argument to accept a `Hash` where the keys are exception types and the values are a single or list of `Regexp` pattern(s) to match against exception messages for retrial.
data/README.md CHANGED
@@ -23,7 +23,7 @@ gem install retriable
23
23
  In your ruby script:
24
24
 
25
25
  ```ruby
26
- require 'retriable'
26
+ require 'retriable', '~> 2.0'
27
27
  ```
28
28
 
29
29
  In your Gemfile:
@@ -66,7 +66,7 @@ end
66
66
 
67
67
  Here are the available options:
68
68
 
69
- `max_tries` (default: 3) - Number of attempts to make at running your code block.
69
+ `tries` (default: 3) - Number of attempts to make at running your code block.
70
70
 
71
71
  `base_interval` (default: 0.5) - The initial interval in seconds between attempts.
72
72
 
@@ -82,7 +82,7 @@ randomized_interval = retry_interval * (random value in range [1 - randomization
82
82
 
83
83
  `max_elapsed_time` (default: 900 (15 min)) - The maximum amount of total time that code is allowed to keep being retried.
84
84
 
85
- `intervals` (default: nil) - Skip generated intervals and provide your own array of intervals in seconds. Setting this option will ignore `max_tries`, `base_interval`, `max_interval`, `rand_factor`, and `multiplier` values.
85
+ `intervals` (default: nil) - Skip generated intervals and provide your own array of intervals in seconds. Setting this option will ignore `tries`, `base_interval`, `max_interval`, `rand_factor`, and `multiplier` values.
86
86
 
87
87
  `timeout` (default: 0) - Number of seconds to allow the code block to run before raising a Timeout::Error
88
88
 
@@ -96,7 +96,7 @@ You can change the global defaults with a `#configure` block:
96
96
 
97
97
  ```ruby
98
98
  Retriable.configure do |c|
99
- c.max_tries = 5
99
+ c.tries = 5
100
100
  c.max_elapsed_time = 3600 # 1 hour
101
101
  end
102
102
  ```
@@ -106,7 +106,7 @@ end
106
106
  `Retriable.retriable` accepts custom arguments. This example will only retry on a `Timeout::Error`, retry 3 times and sleep for a full second before each attempt.
107
107
 
108
108
  ```ruby
109
- Retriable.retriable on: Timeout::Error, max_tries: 3, base_interval: 1 do
109
+ Retriable.retriable on: Timeout::Error, tries: 3, base_interval: 1 do
110
110
  # code here...
111
111
  end
112
112
  ```
@@ -149,7 +149,7 @@ end
149
149
 
150
150
  ### Custom Interval Array
151
151
 
152
- You can also bypass the built-in interval generation and provide your own array of intervals. Supplying your own intervals overrides the `max_tries`, `base_interval`, `max_interval`, `rand_factor`, and `multiplier` parameters.
152
+ You can also bypass the built-in interval generation and provide your own array of intervals. Supplying your own intervals overrides the `tries`, `base_interval`, `max_interval`, `rand_factor`, and `multiplier` parameters.
153
153
 
154
154
  ```ruby
155
155
  Retriable.retriable intervals: [0.5, 1.0, 2.0, 2.5] do
data/lib/retriable.rb CHANGED
@@ -17,7 +17,7 @@ module Retriable
17
17
  end
18
18
 
19
19
  def retriable(
20
- max_tries: config.max_tries,
20
+ tries: config.tries,
21
21
  base_interval: config.base_interval,
22
22
  max_interval: config.max_interval,
23
23
  rand_factor: config.rand_factor,
@@ -33,14 +33,14 @@ module Retriable
33
33
  elapsed_time = -> { Time.now - start_time }
34
34
 
35
35
  if intervals
36
- max_tries = intervals.size
36
+ tries = intervals.size
37
37
  else
38
38
  intervals = ExponentialBackoff.new(
39
- max_tries: max_tries,
40
- base_interval: base_interval,
41
- multiplier: multiplier,
42
- max_interval: max_interval,
43
- rand_factor: rand_factor
39
+ tries: tries,
40
+ base_interval: base_interval,
41
+ multiplier: multiplier,
42
+ max_interval: max_interval,
43
+ rand_factor: rand_factor
44
44
  ).intervals
45
45
  end
46
46
 
@@ -67,7 +67,7 @@ module Retriable
67
67
  end
68
68
 
69
69
  on_retry.call(exception, attempt, elapsed_time.call, interval) if on_retry
70
- raise if attempt >= max_tries || (elapsed_time.call + interval) > max_elapsed_time
70
+ raise if attempt >= tries || (elapsed_time.call + interval) > max_elapsed_time
71
71
  sleep interval if config.sleep_disabled != true
72
72
  end
73
73
  end
@@ -1,7 +1,7 @@
1
1
  module Retriable
2
2
  class Config
3
3
  attr_accessor :sleep_disabled
4
- attr_accessor :max_tries
4
+ attr_accessor :tries
5
5
  attr_accessor :base_interval
6
6
  attr_accessor :max_interval
7
7
  attr_accessor :rand_factor
@@ -14,7 +14,7 @@ module Retriable
14
14
 
15
15
  def initialize
16
16
  @sleep_disabled = false
17
- @max_tries = 3
17
+ @tries = 3
18
18
  @base_interval = 0.5
19
19
  @max_interval = 60
20
20
  @rand_factor = 0.5
@@ -1,24 +1,28 @@
1
1
  module Retriable
2
2
  class ExponentialBackoff
3
- attr_accessor :max_tries, :base_interval, :multiplier, :max_interval, :rand_factor
3
+ attr_accessor :tries
4
+ attr_accessor :base_interval
5
+ attr_accessor :multiplier
6
+ attr_accessor :max_interval
7
+ attr_accessor :rand_factor
4
8
 
5
9
  def initialize(
6
- max_tries: Retriable.config.max_tries,
7
- base_interval: Retriable.config.base_interval,
8
- multiplier: Retriable.config.multiplier,
9
- max_interval: Retriable.config.max_interval,
10
- rand_factor: Retriable.config.rand_factor
10
+ tries: Retriable.config.tries,
11
+ base_interval: Retriable.config.base_interval,
12
+ multiplier: Retriable.config.multiplier,
13
+ max_interval: Retriable.config.max_interval,
14
+ rand_factor: Retriable.config.rand_factor
11
15
  )
12
16
 
13
- @max_tries = max_tries
14
- @base_interval = base_interval
15
- @multiplier = multiplier
16
- @max_interval = max_interval
17
- @rand_factor = rand_factor
17
+ @tries = tries
18
+ @base_interval = base_interval
19
+ @multiplier = multiplier
20
+ @max_interval = max_interval
21
+ @rand_factor = rand_factor
18
22
  end
19
23
 
20
24
  def intervals
21
- intervals = Array.new(max_tries) do |iteration|
25
+ intervals = Array.new(tries) do |iteration|
22
26
  [base_interval * multiplier ** iteration, max_interval].min
23
27
  end
24
28
 
@@ -1,3 +1,3 @@
1
1
  module Retriable
2
- VERSION = "2.0.0.beta4"
2
+ VERSION = "2.0.0.beta5"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -9,8 +9,8 @@ describe Retriable::Config do
9
9
  subject.new.sleep_disabled.must_equal false
10
10
  end
11
11
 
12
- it "max tries defaults to 3" do
13
- subject.new.max_tries.must_equal 3
12
+ it "tries defaults to 3" do
13
+ subject.new.tries.must_equal 3
14
14
  end
15
15
 
16
16
  it "max interval defaults to 60" do
@@ -5,8 +5,8 @@ describe Retriable::ExponentialBackoff do
5
5
  Retriable::ExponentialBackoff
6
6
  end
7
7
 
8
- it "max tries defaults to 3" do
9
- subject.new.max_tries.must_equal 3
8
+ it "tries defaults to 3" do
9
+ subject.new.tries.must_equal 3
10
10
  end
11
11
 
12
12
  it "max interval defaults to 60" do
@@ -22,7 +22,7 @@ describe Retriable::ExponentialBackoff do
22
22
  end
23
23
 
24
24
  it "generates randomized intervals" do
25
- i = subject.new(max_tries: 9).intervals
25
+ i = subject.new(tries: 9).intervals
26
26
  i[0].between?(0.25, 0.75).must_equal true
27
27
  i[1].between?(0.375, 1.125).must_equal true
28
28
  i[2].between?(0.562, 1.687).must_equal true
@@ -36,7 +36,7 @@ describe Retriable::ExponentialBackoff do
36
36
 
37
37
  it "generates 5 non-randomized intervals" do
38
38
  subject.new(
39
- max_tries: 5,
39
+ tries: 5,
40
40
  rand_factor: 0.0
41
41
  ).intervals.must_equal([
42
42
  0.5,
@@ -56,11 +56,11 @@ describe Retriable do
56
56
  end.must_raise TestError
57
57
  end
58
58
 
59
- it "#retriable with 10 max tries" do
59
+ it "#retriable tries 10 times" do
60
60
  attempts = 0
61
61
 
62
62
  subject.retriable(
63
- max_tries: 10
63
+ tries: 10
64
64
  ) do
65
65
  attempts += 1
66
66
  raise EOFError.new if attempts < 10
@@ -91,7 +91,7 @@ describe Retriable do
91
91
  on: [EOFError, ArgumentError],
92
92
  on_retry: handler,
93
93
  rand_factor: 0.0,
94
- max_tries: 9
94
+ tries: 9
95
95
  ) do
96
96
  @attempts += 1
97
97
  raise ArgumentError.new
@@ -111,7 +111,7 @@ describe Retriable do
111
111
 
112
112
  describe "retries with an on_#retriable handler, 6 max retries, and a 0.0 rand_factor" do
113
113
  before do
114
- max_tries = 6
114
+ tries = 6
115
115
  @attempts = 0
116
116
  @time_table = {}
117
117
 
@@ -124,10 +124,10 @@ describe Retriable do
124
124
  on: [EOFError, ArgumentError],
125
125
  on_retry: handler,
126
126
  rand_factor: 0.0,
127
- max_tries: max_tries
127
+ tries: tries
128
128
  ) do
129
129
  @attempts += 1
130
- raise ArgumentError.new if @attempts < max_tries
130
+ raise ArgumentError.new if @attempts < tries
131
131
  end
132
132
  end
133
133
 
@@ -147,7 +147,7 @@ describe Retriable do
147
147
  end
148
148
 
149
149
  it "#retriable has a max interval of 1.5 seconds" do
150
- max_tries = 6
150
+ tries = 6
151
151
  attempts = 0
152
152
  time_table = {}
153
153
 
@@ -159,11 +159,11 @@ describe Retriable do
159
159
  on: EOFError,
160
160
  on_retry: handler,
161
161
  rand_factor: 0.0,
162
- max_tries: max_tries,
162
+ tries: tries,
163
163
  max_interval: 1.5
164
164
  ) do
165
165
  attempts += 1
166
- raise EOFError.new if attempts < max_tries
166
+ raise EOFError.new if attempts < tries
167
167
  end
168
168
 
169
169
  time_table.must_equal({
@@ -226,7 +226,7 @@ describe Retriable do
226
226
  end
227
227
 
228
228
  e = -> do
229
- subject.retriable max_tries: 4, on: { EOFError => nil, TestError => [/foo/, /bar/] }, on_retry: handler do
229
+ subject.retriable tries: 4, on: { EOFError => nil, TestError => [/foo/, /bar/] }, on_retry: handler do
230
230
  attempts += 1
231
231
  case attempts
232
232
  when 1
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retriable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta4
4
+ version: 2.0.0.beta5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Chu