exp_retry 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +18 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +42 -0
- data/Rakefile +7 -0
- data/Readme.md +15 -0
- data/exp-retry.gemspec +20 -0
- data/lib/exp_retry.rb +31 -0
- data/spec/lib/exp_retry_spec.rb +32 -0
- data/spec/spec_helper.rb +10 -0
- metadata +15 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5587b6563afaa1c777f7fadd3f6d1aadd925228a
|
4
|
+
data.tar.gz: 445ad33d5d9172e57aa718c935928103141fdbfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f277a41856af529f43cdc700b0083c428afa872fedbdfd45f7fe0eaf2e9dabcdad23fc6a9a56967bf82ea2b48b707aedff79b1d783b1806f0cee386ae1341efe
|
7
|
+
data.tar.gz: c7d653609f2e31a773031f302dd12bfbf5a401a90425f77aa395900e73f7e21b7443f840cadb9d7ef970586493d1a9b28469580049ba65c24ca1b8f50ff3ca9a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.5.1
|
4
|
+
branches:
|
5
|
+
except:
|
6
|
+
- "/^v[0-9]+\\.[0-9]+\\.[0-9]+(?:-.*)?/"
|
7
|
+
notifications:
|
8
|
+
email:
|
9
|
+
on_success: change
|
10
|
+
on_failure: always
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
exp_retry (0.0.2)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
docile (1.3.1)
|
11
|
+
json (2.1.0)
|
12
|
+
rake (12.3.1)
|
13
|
+
rspec (3.8.0)
|
14
|
+
rspec-core (~> 3.8.0)
|
15
|
+
rspec-expectations (~> 3.8.0)
|
16
|
+
rspec-mocks (~> 3.8.0)
|
17
|
+
rspec-core (3.8.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-expectations (3.8.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-mocks (3.8.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-support (3.8.0)
|
26
|
+
simplecov (0.16.1)
|
27
|
+
docile (~> 1.1)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov-html (~> 0.10.0)
|
30
|
+
simplecov-html (0.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
exp_retry!
|
37
|
+
rake (~> 12.2, >= 12.2.1)
|
38
|
+
rspec (~> 3.7, >= 3.7.0)
|
39
|
+
simplecov (~> 0.15, >= 0.15.1)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
1.16.4
|
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Exponential Retry
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/jfiander/exp-retry.svg)](https://travis-ci.org/jfiander/exp-retry)
|
4
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/4c8be06f11872994f2c7/maintainability)](https://codeclimate.com/github/jfiander/exp-retry/maintainability)
|
5
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/4c8be06f11872994f2c7/test_coverage)](https://codeclimate.com/github/jfiander/exp-retry/test_coverage)
|
6
|
+
|
7
|
+
A simple exponential backoff retry wrapper.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
ExpRetry.new.call do
|
13
|
+
something_unreliable
|
14
|
+
end
|
15
|
+
```
|
data/exp-retry.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'exp_retry'
|
3
|
+
s.version = '0.0.2'
|
4
|
+
s.date = '2018-10-16'
|
5
|
+
s.summary = 'Exponential backoff retry'
|
6
|
+
s.description = 'A simple exponential backoff retry wrapper.'
|
7
|
+
s.homepage = 'http://rubygems.org/gems/exp_retry'
|
8
|
+
s.license = 'GPL-3.0'
|
9
|
+
s.authors = ['Julian Fiander']
|
10
|
+
s.email = 'julian@fiander.one'
|
11
|
+
s.require_paths = %w[lib spec doc]
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
14
|
+
|
15
|
+
s.required_ruby_version = '~> 2.4'
|
16
|
+
|
17
|
+
s.add_development_dependency 'rake', '~> 12.2', '>= 12.2.1'
|
18
|
+
s.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
|
19
|
+
s.add_development_dependency 'simplecov', '~> 0.15', '>= 0.15.1'
|
20
|
+
end
|
data/lib/exp_retry.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Exponential backoff retry wrapper
|
4
|
+
class ExpRetry
|
5
|
+
def initialize(retries: 3)
|
6
|
+
@retries = retries
|
7
|
+
end
|
8
|
+
|
9
|
+
def call
|
10
|
+
yield if block_given?
|
11
|
+
rescue StandardError => e
|
12
|
+
check(e)
|
13
|
+
retry
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def check(e)
|
19
|
+
retried > @retries ? raise(e) : delay(e)
|
20
|
+
end
|
21
|
+
|
22
|
+
def retried
|
23
|
+
@retried ||= 0
|
24
|
+
@retried += 1
|
25
|
+
end
|
26
|
+
|
27
|
+
def delay(e)
|
28
|
+
puts "*** #{e}. Retrying in #{2**@retried} seconds..."
|
29
|
+
sleep 2**@retried
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe ExpRetry do
|
6
|
+
it 'should allow normal execution' do
|
7
|
+
r = ExpRetry.new.call do
|
8
|
+
'Something'
|
9
|
+
end
|
10
|
+
|
11
|
+
expect(r).to eql('Something')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should allow normal execution' do
|
15
|
+
@fail_once = 1
|
16
|
+
r = ExpRetry.new.call do
|
17
|
+
if @fail_once.positive?
|
18
|
+
@fail_once -= 1
|
19
|
+
raise 'Fail once'
|
20
|
+
end
|
21
|
+
'Something'
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(r).to eql('Something')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should raise after too many retries' do
|
28
|
+
expect do
|
29
|
+
ExpRetry.new.call { raise 'Fail forever' }
|
30
|
+
end.to raise_error(RuntimeError, 'Fail forever')
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exp_retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Fiander
|
@@ -75,7 +75,17 @@ email: julian@fiander.one
|
|
75
75
|
executables: []
|
76
76
|
extensions: []
|
77
77
|
extra_rdoc_files: []
|
78
|
-
files:
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- Rakefile
|
84
|
+
- Readme.md
|
85
|
+
- exp-retry.gemspec
|
86
|
+
- lib/exp_retry.rb
|
87
|
+
- spec/lib/exp_retry_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
79
89
|
homepage: http://rubygems.org/gems/exp_retry
|
80
90
|
licenses:
|
81
91
|
- GPL-3.0
|
@@ -102,4 +112,6 @@ rubygems_version: 2.6.11
|
|
102
112
|
signing_key:
|
103
113
|
specification_version: 4
|
104
114
|
summary: Exponential backoff retry
|
105
|
-
test_files:
|
115
|
+
test_files:
|
116
|
+
- spec/lib/exp_retry_spec.rb
|
117
|
+
- spec/spec_helper.rb
|