retryable 2.0.3 → 2.0.4

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.
@@ -1,3 +1,9 @@
1
+ ## Retryable 2.0.4 ##
2
+
3
+ * :infinite value is now available as :tries paramater. Use it for retrying your blocks infinitely until it stops failing.
4
+ * :sleep_method parameter has been added. This can be very useful when you are working with Celluloid which implements its own version of the method sleep.
5
+ Use `:sleep_method => Celluloid.method(:sleep)` in such cases.
6
+
1
7
  ## Retryable 2.0.3 ##
2
8
 
3
9
  * gemspec contains explicit licence option from now on(MIT)
data/README.md CHANGED
@@ -2,6 +2,7 @@ retryable gem
2
2
  =====
3
3
 
4
4
  [![Build Status](https://travis-ci.org/nfedyashev/retryable.png?branch=master)](https://travis-ci.org/nfedyashev/retryable)
5
+ [![Dependency Status](https://www.versioneye.com/ruby/retryable/badge.svg)](https://www.versioneye.com/ruby/retryable)
5
6
 
6
7
  Description
7
8
  --------
@@ -9,7 +10,7 @@ Description
9
10
  Runs a code block, and retries it when an exception occurs. It's great when
10
11
  working with flakey webservices (for example).
11
12
 
12
- It's configured using five optional parameters `:tries`, `:on`, `:sleep`, `:matching`, `:ensure`, `:exception_cb`, `:not` and
13
+ It's configured using several optional parameters `:tries`, `:on`, `:sleep`, `:matching`, `:ensure`, `:exception_cb`, `:not`, `:sleep_method` and
13
14
  runs the passed block. Should an exception occur, it'll retry for (n-1) times.
14
15
 
15
16
  Should the number of retries be reached without success, the last exception
@@ -29,6 +30,13 @@ Retryable.retryable(:tries => 3, :on => OpenURI::HTTPError) do
29
30
  end
30
31
  ```
31
32
 
33
+ Try the block forever.
34
+ ```ruby
35
+ Retryable.retryable(:tries => :infinite) do
36
+ # some code
37
+ end
38
+ ```
39
+
32
40
  Do _something_, retry up to four times for either `ArgumentError` or
33
41
  `TimeoutError` exceptions.
34
42
 
@@ -56,7 +64,7 @@ end
56
64
 
57
65
  ## Defaults
58
66
 
59
- :tries => 2, :on => StandardError, :sleep => 1, :matching => /.*/, :ensure => Proc.new { }, :exception_cb => Proc.new { }, :not => []
67
+ :tries => 2, :on => StandardError, :sleep => 1, :matching => /.*/, :ensure => Proc.new { }, :exception_cb => Proc.new { }, :not => [], :sleep_method => lambda { |n| Kernel.sleep(n) }
60
68
 
61
69
  Retryable also could be configured globally to change those defaults:
62
70
 
@@ -69,6 +77,7 @@ Retryable.configure do |config|
69
77
  config.sleep = 1
70
78
  config.tries = 2
71
79
  config.not = []
80
+ config.sleep_method = Celluloid.method(:sleep)
72
81
  end
73
82
  ```
74
83
 
@@ -145,6 +154,17 @@ end
145
154
 
146
155
  ```
147
156
 
157
+ Specify the sleep method to use
158
+ --------
159
+ This can be very useful when you are working with [Celluloid](https://github.com/celluloid/celluloid)
160
+ which implements its own version of the method sleep.
161
+
162
+ ```
163
+ Retryable.retryable(:sleep_method => Celluloid.method(:sleep)) do
164
+ retrieve_url
165
+ end
166
+ ```
167
+
148
168
  Supported Ruby Versions
149
169
  -------
150
170
 
@@ -49,7 +49,8 @@ module Retryable
49
49
  :matching => self.configuration.matching,
50
50
  :ensure => self.configuration.ensure,
51
51
  :exception_cb => self.configuration.exception_cb,
52
- :not => self.configuration.not
52
+ :not => self.configuration.not,
53
+ :sleep_method => self.configuration.sleep_method
53
54
  }
54
55
 
55
56
  check_for_invalid_options(options, opts)
@@ -70,11 +71,12 @@ module Retryable
70
71
  rescue *on_exception => exception
71
72
  raise unless configuration.enabled?
72
73
  raise unless exception.message =~ opts[:matching]
73
- raise if retries+1 >= tries
74
+ raise if tries != :infinite && retries+1 >= tries
74
75
 
75
76
  # Interrupt Exception could be raised while sleeping
76
77
  begin
77
- Kernel.sleep opts[:sleep].respond_to?(:call) ? opts[:sleep].call(retries) : opts[:sleep]
78
+ seconds = opts[:sleep].respond_to?(:call) ? opts[:sleep].call(retries) : opts[:sleep]
79
+ opts[:sleep_method].call(seconds)
78
80
  rescue *not_exception
79
81
  raise
80
82
  rescue *on_exception
@@ -8,7 +8,8 @@ module Retryable
8
8
  :on,
9
9
  :sleep,
10
10
  :tries,
11
- :not
11
+ :not,
12
+ :sleep_method
12
13
  ].freeze
13
14
 
14
15
  attr_accessor :ensure
@@ -18,6 +19,7 @@ module Retryable
18
19
  attr_accessor :sleep
19
20
  attr_accessor :tries
20
21
  attr_accessor :not
22
+ attr_accessor :sleep_method
21
23
 
22
24
  attr_accessor :enabled
23
25
 
@@ -31,7 +33,7 @@ module Retryable
31
33
  @sleep = 1
32
34
  @tries = 2
33
35
  @not = []
34
-
36
+ @sleep_method = lambda do |seconds| Kernel.sleep(seconds) end
35
37
  @enabled = true
36
38
  end
37
39
 
@@ -2,7 +2,7 @@ module Retryable
2
2
  class Version
3
3
  MAJOR = 2 unless defined? Retryable::Version::MAJOR
4
4
  MINOR = 0 unless defined? Retryable::Version::MINOR
5
- PATCH = 3 unless defined? Retryable::Version::PATCH
5
+ PATCH = 4 unless defined? Retryable::Version::PATCH
6
6
 
7
7
  class << self
8
8
 
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.add_development_dependency 'bundler', '~> 1.0'
6
6
  gem.authors = ["Nikita Fedyashev", "Carlo Zottmann", "Chu Yeow"]
7
7
  gem.description = %q{Retryable#retryable, allow for retrying of code blocks.}
8
- gem.email = %q{loci.master@gmail.com}
8
+ gem.email = %q{nfedyashev@gmail.com}
9
9
  gem.files = %w(CHANGELOG.md LICENSE.md README.md Rakefile retryable.gemspec)
10
10
  gem.files += Dir.glob("lib/**/*.rb")
11
11
  gem.files += Dir.glob("spec/**/*")
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ require 'timeout'
2
3
 
3
4
  RSpec.describe 'Retryable.retryable' do
4
5
  before(:each) do
@@ -67,6 +68,16 @@ RSpec.describe 'Retryable.retryable' do
67
68
  expect(@try_count).to eq(3)
68
69
  end
69
70
 
71
+ it 'retries infinitely' do
72
+ expect do
73
+ Timeout::timeout(3) do
74
+ count_retryable(:tries => :infinite, :sleep => 0.1) { |tries, ex| raise StandardError }
75
+ end
76
+ end.to raise_error Timeout::Error
77
+
78
+ expect(@try_count).to be > 10
79
+ end
80
+
70
81
  it 'retries on default exception' do
71
82
  expect(Kernel).to receive(:sleep).once.with(1)
72
83
 
@@ -81,6 +92,14 @@ RSpec.describe 'Retryable.retryable' do
81
92
  end.to raise_error RangeError
82
93
  end
83
94
 
95
+ it 'calls :sleep_method option' do
96
+ sleep_method = double
97
+ expect(sleep_method).to receive(:call).twice
98
+ expect do
99
+ Retryable.retryable(:tries => 3, :sleep_method => sleep_method) { |tries, ex| raise RangeError if tries < 9}
100
+ end.to raise_error RangeError
101
+ end
102
+
84
103
  it 'does not retry any exception if :on is empty list' do
85
104
  expect do
86
105
  count_retryable(:on => []) { raise }
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/../lib/retryable'
2
2
  require 'rspec'
3
+ require 'pry'
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.disable_monkey_patching!
metadata CHANGED
@@ -1,74 +1,97 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: retryable
3
- version: !ruby/object:Gem::Version
4
- version: 2.0.3
3
+ version: !ruby/object:Gem::Version
4
+ hash: 7
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 4
10
+ version: 2.0.4
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Nikita Fedyashev
8
14
  - Carlo Zottmann
9
15
  - Chu Yeow
10
16
  autorequire:
11
17
  bindir: bin
12
18
  cert_chain: []
13
- date: 2015-11-05 00:00:00.000000000 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
19
+
20
+ date: 2016-07-14 00:00:00 +03:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
16
24
  name: bundler
17
- requirement: !ruby/object:Gem::Requirement
18
- requirements:
19
- - - "~>"
20
- - !ruby/object:Gem::Version
21
- version: '1.0'
22
- type: :development
23
25
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - "~>"
27
- - !ruby/object:Gem::Version
28
- version: '1.0'
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 15
32
+ segments:
33
+ - 1
34
+ - 0
35
+ version: "1.0"
36
+ type: :development
37
+ version_requirements: *id001
29
38
  description: Retryable#retryable, allow for retrying of code blocks.
30
- email: loci.master@gmail.com
39
+ email: nfedyashev@gmail.com
31
40
  executables: []
41
+
32
42
  extensions: []
43
+
33
44
  extra_rdoc_files: []
34
- files:
45
+
46
+ files:
35
47
  - CHANGELOG.md
36
48
  - LICENSE.md
37
49
  - README.md
38
50
  - Rakefile
39
- - lib/retryable.rb
51
+ - retryable.gemspec
40
52
  - lib/retryable/configuration.rb
41
53
  - lib/retryable/version.rb
42
- - retryable.gemspec
54
+ - lib/retryable.rb
43
55
  - spec/lib/configuration_spec.rb
44
56
  - spec/lib/retryable_spec.rb
45
57
  - spec/spec_helper.rb
58
+ has_rdoc: true
46
59
  homepage: http://github.com/nfedyashev/retryable
47
- licenses:
60
+ licenses:
48
61
  - MIT
49
- metadata: {}
50
62
  post_install_message:
51
63
  rdoc_options: []
52
- require_paths:
64
+
65
+ require_paths:
53
66
  - lib
54
- required_ruby_version: !ruby/object:Gem::Requirement
55
- requirements:
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
56
70
  - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
- required_rubygems_version: !ruby/object:Gem::Requirement
60
- requirements:
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
61
79
  - - ">="
62
- - !ruby/object:Gem::Version
80
+ - !ruby/object:Gem::Version
81
+ hash: 23
82
+ segments:
83
+ - 1
84
+ - 3
85
+ - 6
63
86
  version: 1.3.6
64
87
  requirements: []
88
+
65
89
  rubyforge_project:
66
- rubygems_version: 2.4.6
90
+ rubygems_version: 1.6.2
67
91
  signing_key:
68
- specification_version: 4
92
+ specification_version: 3
69
93
  summary: Retryable#retryable, allow for retrying of code blocks.
70
- test_files:
94
+ test_files:
71
95
  - spec/lib/configuration_spec.rb
72
96
  - spec/lib/retryable_spec.rb
73
97
  - spec/spec_helper.rb
74
- has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 86143d2b49dbb2f7d5c38fd48eb82ff3e43dd79e
4
- data.tar.gz: 740cf211de57aa3579c4ad26ef6f360a23b8b257
5
- SHA512:
6
- metadata.gz: 8efc21fece286e757cb446010f94aab27ca50beeb7336f3daf00b14f6021285357f0cc5a2cc50df2f62772fa0e39768f0b9a001b822aa7024084a511fa7d41ae
7
- data.tar.gz: 1c1d0912ec01b1fc7319e9e8ea7d903c14baf4117f33e1b1edcefd11811344b4a23ead38d9dabdbc50dc332acfa64483f35651a224569f00432111d0a881ceaf