exponential_backoff 0.1.0 → 0.2.0
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/README.md +22 -3
- data/exponential_backoff.gemspec +2 -2
- data/lib/exponential_backoff.rb +14 -7
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ba61c347fad475b50607992cdbb7576a5a0cc92b
|
|
4
|
+
data.tar.gz: 5cf04b6918d74d7e6a8a9eba18d630942cdaa458
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 069fcd523020681fcf1e6e853c0602466a7240272f3bc6d74fb7a2b1148df152994e600d4cfa1c14e100ed2cb285d495dfe485d7f974d52632059afb990d72bb
|
|
7
|
+
data.tar.gz: f620fda204a7540e58a459158f05ec0215e538b1448eabc655965b3ec15dd9ff7adeadf77b6bd642c2000ef8571d1abc2575e7537e5ce115b8e32613882b73e1
|
data/README.md
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Exponential Backoff
|
|
2
|
+
### _Simple Exponential Backoff in Ruby_
|
|
3
|
+
---
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
$ gem install exponential_backoff
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
require 'exponential_backoff'
|
|
13
|
+
|
|
14
|
+
ExponentialBackoff.try(3) do
|
|
15
|
+
res = Hippie.get(url)
|
|
16
|
+
fail if res.error?
|
|
17
|
+
end
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## API
|
|
21
|
+
```ruby
|
|
22
|
+
ExponentialBackoff.try(max_number_of_tries) { request }
|
|
23
|
+
```
|
data/exponential_backoff.gemspec
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = 'exponential_backoff'
|
|
3
|
-
s.version = '0.
|
|
3
|
+
s.version = '0.2.0'
|
|
4
4
|
s.summary = 'Exponential Backoff'
|
|
5
5
|
s.description = 'Simple Exponential Backoff in Ruby'
|
|
6
6
|
s.author = 'Martin Manelli'
|
|
7
7
|
s.email = 'manelli.ml@gmail.com'
|
|
8
|
-
s.homepage = 'http://github.com/manelli/
|
|
8
|
+
s.homepage = 'http://github.com/manelli/exponential_backoff'
|
|
9
9
|
s.license = 'MIT'
|
|
10
10
|
s.require_paths = ['lib']
|
|
11
11
|
|
data/lib/exponential_backoff.rb
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
module ExponentialBackoff
|
|
2
|
-
RequestNotSucceded = Class.new(StandardError)
|
|
3
|
-
|
|
4
2
|
def self.try(max_tries, &block)
|
|
3
|
+
errors = []
|
|
5
4
|
1.upto max_tries do |n|
|
|
6
5
|
begin
|
|
7
|
-
return
|
|
8
|
-
rescue =>
|
|
6
|
+
return block.call
|
|
7
|
+
rescue => err
|
|
8
|
+
errors << err
|
|
9
9
|
wait(n)
|
|
10
10
|
next
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
|
-
raise
|
|
13
|
+
raise FailedRequest.new(errors)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
private
|
|
17
|
-
|
|
18
16
|
def self.wait(iteration)
|
|
19
17
|
seconds = rand(1..1000) * 0.001
|
|
20
18
|
waiting_time = (2**iteration + seconds).ceil
|
|
21
19
|
sleep(waiting_time)
|
|
22
20
|
end
|
|
21
|
+
private_class_method :wait
|
|
22
|
+
|
|
23
|
+
class FailedRequest < StandardError
|
|
24
|
+
attr_reader :errors
|
|
25
|
+
|
|
26
|
+
def initialize(errors)
|
|
27
|
+
@errors = errors
|
|
28
|
+
end
|
|
29
|
+
end
|
|
23
30
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: exponential_backoff
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Martin Manelli
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-12-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Simple Exponential Backoff in Ruby
|
|
14
14
|
email: manelli.ml@gmail.com
|
|
@@ -20,7 +20,7 @@ files:
|
|
|
20
20
|
- README.md
|
|
21
21
|
- exponential_backoff.gemspec
|
|
22
22
|
- lib/exponential_backoff.rb
|
|
23
|
-
homepage: http://github.com/manelli/
|
|
23
|
+
homepage: http://github.com/manelli/exponential_backoff
|
|
24
24
|
licenses:
|
|
25
25
|
- MIT
|
|
26
26
|
metadata: {}
|
|
@@ -40,8 +40,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
40
40
|
version: '0'
|
|
41
41
|
requirements: []
|
|
42
42
|
rubyforge_project:
|
|
43
|
-
rubygems_version: 2.4.
|
|
43
|
+
rubygems_version: 2.4.4
|
|
44
44
|
signing_key:
|
|
45
45
|
specification_version: 4
|
|
46
46
|
summary: Exponential Backoff
|
|
47
47
|
test_files: []
|
|
48
|
+
has_rdoc:
|