exp_retry 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcf20e1954c741739c256c324c0511bd503d470177bddea6e440954df9b8b0e3
4
- data.tar.gz: a698f18df11aea017d8a38c86c9840637008df8d0f94e7ac36cd50630a8eb3b1
3
+ metadata.gz: 5534510118f308e1d03b685d72f02678c08d79e55884b2be0f4424906389e3a0
4
+ data.tar.gz: 8719251b81b72bc9725a60ca7567db1794daea3a2914bd8556c75c73b1f36509
5
5
  SHA512:
6
- metadata.gz: 2e8d7f73a2a9e089035b92931f1a10da74223d37721ac5791f3e77e33845b120a1181203cb18d1aea5f906b1cf82322d8d743f1233f3cd7d97232bf7785de72b
7
- data.tar.gz: e1157a628e18cf70532756d65edeeb32c456160b6c6897a6c7c379dedea7f498bf45adcd27288dafdcff70f4cd5159ac6c6d45c9d7fb26788c87f0d3948e0168
6
+ metadata.gz: 81d1d14c9dd4c3ce441f6f1b243c72c7cfc413bc1679a0ad867d9a9c0eee79127462baeb738a36bd360a6598e05b764fe4da2a81af132ad8a084dfa5ae0645ca
7
+ data.tar.gz: 6a5fd391e10cab2341ba4fe3d7022303edefaac65901b41da36865e9e14364b8ba35be46add5cbb2881144a92924835748a9af436de5a2fc6ca78ab239f3636a
data/.travis.yml CHANGED
@@ -8,6 +8,8 @@ notifications:
8
8
  email:
9
9
  on_success: change
10
10
  on_failure: always
11
+ before_install:
12
+ - gem install bundler -v '< 2'
11
13
  before_script:
12
14
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
13
15
  - chmod +x ./cc-test-reporter
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- exp_retry (0.0.12)
4
+ exp_retry (0.0.13)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exp-retry.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'exp_retry'
5
- s.version = '0.0.12'
6
- s.date = '2019-06-15'
5
+ s.version = '0.0.13'
6
+ s.date = '2019-07-11'
7
7
  s.summary = 'Exponential backoff retry'
8
8
  s.description = 'A simple exponential backoff retry wrapper.'
9
9
  s.homepage = 'http://rubygems.org/gems/exp_retry'
data/lib/exp_retry.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Exponential backoff retry wrapper
4
4
  class ExpRetry
5
5
  attr_accessor :retries
6
- attr_reader :exception
6
+ attr_reader :exception, :tried
7
7
 
8
8
  def self.for(retries: 3, exception: StandardError, verbose: false)
9
9
  new(retries: retries, exception: exception, verbose: verbose).call { yield }
@@ -11,6 +11,7 @@ class ExpRetry
11
11
 
12
12
  def initialize(retries: 3, exception: StandardError, wait: 1000, verbose: false)
13
13
  @retries = retries
14
+ @tried = 0
14
15
  @exception = exception
15
16
  @verbose = verbose
16
17
  @wait = wait
@@ -26,14 +27,14 @@ class ExpRetry
26
27
  private
27
28
 
28
29
  def check(exception)
29
- raise(exception) unless retries.positive?
30
+ raise(exception) if tried >= retries
30
31
 
31
- decrement
32
+ increment
32
33
  delay
33
34
  end
34
35
 
35
- def decrement
36
- @retries -= 1
36
+ def increment
37
+ @tried += 1
37
38
  end
38
39
 
39
40
  def delay
@@ -43,6 +44,6 @@ private
43
44
  end
44
45
 
45
46
  def time
46
- 2**retries * (@wait.to_f / 1000)
47
+ 2**tried * (@wait.to_f / 1000)
47
48
  end
48
49
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe ExpRetry do
6
- let(:wait) { 10 }
6
+ let(:wait) { 50 }
7
7
 
8
8
  it 'allows normal execution' do
9
9
  r = described_class.new.call { 'Something' }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exp_retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-15 00:00:00.000000000 Z
11
+ date: 2019-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake