retriable 3.0.1 → 3.0.2
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 +4 -4
- data/.travis.yml +5 -5
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/retriable.rb +14 -11
- data/lib/retriable/config.rb +37 -23
- data/lib/retriable/exponential_backoff.rb +19 -10
- data/lib/retriable/version.rb +1 -1
- data/spec/config_spec.rb +6 -0
- data/spec/retriable_spec.rb +12 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfe5a1956e7b8921928094fd4306632da5852693
|
4
|
+
data.tar.gz: bc171d15fa1f55ce45151f6e6ce6976b2082a415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80395340aa4890214aeb12f331904da265f42af80d4e8bd7400e532d7a47f4828abc659f7ae629a74f6d16ce77f1e88b23fc8518ca4531087d23a566ec5bcacc
|
7
|
+
data.tar.gz: c8385720ed1095508eae24dc918eb620ea4715b13d38ef7d2c921abd65f9fb05f6e95065307be644819405a1d9411e20961e95e06b734aae1333b54c3f45745d
|
data/.travis.yml
CHANGED
@@ -5,12 +5,12 @@ language: ruby
|
|
5
5
|
rvm:
|
6
6
|
- 2.0.0
|
7
7
|
- 2.1.10
|
8
|
-
- 2.2.
|
9
|
-
- 2.3.
|
10
|
-
- 2.4.
|
8
|
+
- 2.2.7
|
9
|
+
- 2.3.4
|
10
|
+
- 2.4.1
|
11
11
|
- rbx
|
12
12
|
- jruby-9.0.5.0
|
13
|
-
- jruby-9.1.
|
13
|
+
- jruby-9.1.8.0
|
14
14
|
- ruby-head
|
15
15
|
- jruby-head
|
16
16
|
|
@@ -23,7 +23,7 @@ matrix:
|
|
23
23
|
before_install:
|
24
24
|
- gem update --system
|
25
25
|
- gem install bundler
|
26
|
-
|
26
|
+
|
27
27
|
addons:
|
28
28
|
code_climate:
|
29
29
|
repo_token: 20a1139ef1830b4f813a10a03d90e8aa179b5226f75e75c5a949b25756ebf558
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/retriable.rb
CHANGED
@@ -15,16 +15,19 @@ module Retriable
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def retriable(opts = {})
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
local_config = opts.empty? ? config : Config.new(config.to_h.merge(opts))
|
19
|
+
|
20
|
+
tries = local_config.tries
|
21
|
+
base_interval = local_config.base_interval
|
22
|
+
max_interval = local_config.max_interval
|
23
|
+
rand_factor = local_config.rand_factor
|
24
|
+
multiplier = local_config.multiplier
|
25
|
+
max_elapsed_time = local_config.max_elapsed_time
|
26
|
+
intervals = local_config.intervals
|
27
|
+
timeout = local_config.timeout
|
28
|
+
on = local_config.on
|
29
|
+
on_retry = local_config.on_retry
|
30
|
+
sleep_disabled = local_config.sleep_disabled
|
28
31
|
|
29
32
|
start_time = Time.now
|
30
33
|
elapsed_time = -> { Time.now - start_time }
|
@@ -58,7 +61,7 @@ module Retriable
|
|
58
61
|
interval = intervals[index]
|
59
62
|
on_retry.call(exception, try, elapsed_time.call, interval) if on_retry
|
60
63
|
raise if try >= tries || (elapsed_time.call + interval) > max_elapsed_time
|
61
|
-
sleep interval if
|
64
|
+
sleep interval if sleep_disabled != true
|
62
65
|
end
|
63
66
|
end
|
64
67
|
end
|
data/lib/retriable/config.rb
CHANGED
@@ -1,29 +1,43 @@
|
|
1
|
+
require_relative "exponential_backoff"
|
2
|
+
|
1
3
|
module Retriable
|
2
4
|
class Config
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
attr_accessor
|
13
|
-
|
5
|
+
ATTRIBUTES = ExponentialBackoff::ATTRIBUTES + [
|
6
|
+
:sleep_disabled,
|
7
|
+
:max_elapsed_time,
|
8
|
+
:intervals,
|
9
|
+
:timeout,
|
10
|
+
:on,
|
11
|
+
:on_retry,
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
attr_accessor(*ATTRIBUTES)
|
15
|
+
|
16
|
+
def initialize(opts = {})
|
17
|
+
backoff = ExponentialBackoff.new
|
18
|
+
|
19
|
+
@tries = backoff.tries
|
20
|
+
@base_interval = backoff.base_interval
|
21
|
+
@max_interval = backoff.max_interval
|
22
|
+
@rand_factor = backoff.rand_factor
|
23
|
+
@multiplier = backoff.multiplier
|
24
|
+
@sleep_disabled = false
|
25
|
+
@max_elapsed_time = 900 # 15 min
|
26
|
+
@intervals = nil
|
27
|
+
@timeout = nil
|
28
|
+
@on = [StandardError]
|
29
|
+
@on_retry = nil
|
30
|
+
|
31
|
+
opts.each do |k, v|
|
32
|
+
raise ArgumentError, "#{k} is not a valid option" if !ATTRIBUTES.include?(k)
|
33
|
+
instance_variable_set(:"@#{k}", v)
|
34
|
+
end
|
35
|
+
end
|
14
36
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@max_interval = 60
|
20
|
-
@rand_factor = 0.5
|
21
|
-
@multiplier = 1.5
|
22
|
-
@max_elapsed_time = 900 # 15 min
|
23
|
-
@intervals = nil
|
24
|
-
@timeout = nil
|
25
|
-
@on = [StandardError]
|
26
|
-
@on_retry = nil
|
37
|
+
def to_h
|
38
|
+
ATTRIBUTES.each_with_object({}) do |key, hash|
|
39
|
+
hash[key] = public_send(key)
|
40
|
+
end
|
27
41
|
end
|
28
42
|
end
|
29
43
|
end
|
@@ -1,17 +1,26 @@
|
|
1
1
|
module Retriable
|
2
2
|
class ExponentialBackoff
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
ATTRIBUTES = [
|
4
|
+
:tries,
|
5
|
+
:base_interval,
|
6
|
+
:multiplier,
|
7
|
+
:max_interval,
|
8
|
+
:rand_factor,
|
9
|
+
].freeze
|
10
|
+
|
11
|
+
attr_accessor(*ATTRIBUTES)
|
8
12
|
|
9
13
|
def initialize(opts = {})
|
10
|
-
@tries =
|
11
|
-
@base_interval =
|
12
|
-
@max_interval =
|
13
|
-
@rand_factor =
|
14
|
-
@multiplier =
|
14
|
+
@tries = 3
|
15
|
+
@base_interval = 0.5
|
16
|
+
@max_interval = 60
|
17
|
+
@rand_factor = 0.5
|
18
|
+
@multiplier = 1.5
|
19
|
+
|
20
|
+
opts.each do |k, v|
|
21
|
+
raise ArgumentError, "#{k} is not a valid option" if !ATTRIBUTES.include?(k)
|
22
|
+
instance_variable_set(:"@#{k}", v)
|
23
|
+
end
|
15
24
|
end
|
16
25
|
|
17
26
|
def intervals
|
data/lib/retriable/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -44,4 +44,10 @@ describe Retriable::Config do
|
|
44
44
|
it "on retry handler defaults to nil" do
|
45
45
|
expect(subject.new.on_retry).must_be_nil
|
46
46
|
end
|
47
|
+
|
48
|
+
it "raises errors on invalid configuration" do
|
49
|
+
assert_raises ArgumentError do
|
50
|
+
subject.new(does_not_exist: 123)
|
51
|
+
end
|
52
|
+
end
|
47
53
|
end
|
data/spec/retriable_spec.rb
CHANGED
@@ -364,4 +364,16 @@ describe Retriable do
|
|
364
364
|
|
365
365
|
expect(tries).must_equal 2
|
366
366
|
end
|
367
|
+
|
368
|
+
it "raises NoMethodError on invalid configuration" do
|
369
|
+
assert_raises NoMethodError do
|
370
|
+
Retriable.configure { |c| c.does_not_exist = 123 }
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
it "raises ArgumentError on invalid option on #retriable" do
|
375
|
+
assert_raises ArgumentError do
|
376
|
+
Retriable.retriable(does_not_exist: 123)
|
377
|
+
end
|
378
|
+
end
|
367
379
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retriable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Chu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.6.
|
145
|
+
rubygems_version: 2.6.11
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Retriable is an simple DSL to retry failed code blocks with randomized exponential
|