retriable 1.3.3 → 1.3.3.1

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.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  .bundle
5
5
  Gemfile.lock
6
6
  pkg/*
7
+ .idea
@@ -3,6 +3,7 @@ rvm:
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
+ - 2.0.0
6
7
  - jruby-18mode # JRuby in 1.8 mode
7
8
  - jruby-19mode # JRuby in 1.9 mode
8
9
  - rbx-18mode
@@ -1,3 +1,9 @@
1
+ ## 1.3.3.1
2
+ * Allow sleep parameter to be a proc/lambda to allow for exponential backoff.
3
+
4
+ ## 1.3.3
5
+ * sleep after executing the retry block, so there's no wait on the first call (molfar)
6
+
1
7
  ## 1.3.2
2
8
  * Clean up option defaults.
3
9
  * By default, rescue StandardError and Timeout::Error instead of [Exception](http://www.mikeperham.com/2012/03/03/the-perils-of-rescue-exception).
@@ -22,4 +28,4 @@
22
28
  * Forked the retryable-rb repo.
23
29
  * Extend the Kernel module with the retriable method so you can use it anywhere without having to include it in every class.
24
30
  * Update gemspec, Gemfile, and Raketask.
25
- * Remove echoe dependency.
31
+ * Remove echoe dependency.
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in retriable.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -87,6 +87,15 @@ retriable :interval => (200/1000.0), :timeout => (500/1000.0) do
87
87
  end
88
88
  ```
89
89
 
90
+ If you'd like exponential backoff, interval can take a Proc
91
+
92
+ ```ruby
93
+ # with exponential back-off - sleep 4, 16, 64, 256, give up
94
+ retryable :times => 4, :interval => lambda {|attempts| 4 ** attempts} do
95
+ # code here...
96
+ end
97
+ ```
98
+
90
99
  Retriable also provides a callback called `:on_retry` that will run after an exception is rescued. This callback provides the number of `tries`, and the `exception` that was raised in the current attempt. As these are specified in a `Proc`, unnecessary variables can be left out of the parameter list.
91
100
 
92
101
  ```ruby
@@ -141,4 +150,4 @@ end
141
150
  Credits
142
151
  -------
143
152
 
144
- Retriable was originally forked from the retryable-rb gem by [Robert Sosinski](https://github.com/robertsosinski), which in turn originally inspired by code written by [Michael Celona](http://github.com/mcelona) and later assisted by [David Malin](http://github.com/dmalin). The [attempt](https://rubygems.org/gems/attempt) gem by Daniel J. Berger was also an inspiration.
153
+ Retriable was originally forked from the retryable-rb gem by [Robert Sosinski](https://github.com/robertsosinski), which in turn originally inspired by code written by [Michael Celona](http://github.com/mcelona) and later assisted by [David Malin](http://github.com/dmalin). The [attempt](https://rubygems.org/gems/attempt) gem by Daniel J. Berger was also an inspiration.
@@ -35,7 +35,10 @@ module Retriable
35
35
  if @tries > 0
36
36
  count += 1
37
37
  @on_retry.call(exception, count) if @on_retry
38
- sleep @interval if @interval > 0
38
+
39
+ sleep_for = @interval.respond_to?(:call) ? @interval.call(count) : @interval
40
+ sleep sleep_for if sleep_for > 0
41
+
39
42
  retry
40
43
  else
41
44
  raise
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Retriable
4
- VERSION = '1.3.3'
5
- end
4
+ VERSION = '1.3.3.1'
5
+ end
@@ -43,4 +43,19 @@ class RetriableTest < MiniTest::Unit::TestCase
43
43
  rescue ArgumentError
44
44
  assert_equal 5, i
45
45
  end
46
- end
46
+
47
+ def test_with_interval_proc
48
+ was_called = false
49
+
50
+ sleeper = Proc.new do |attempts|
51
+ was_called = true
52
+ attempts
53
+ end
54
+
55
+ retriable :on => EOFError, :interval => sleeper do |h|
56
+ raise EOFError.new
57
+ end
58
+ rescue
59
+ assert_equal was_called, true
60
+ end
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retriable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-14 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -78,21 +78,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  - - ! '>='
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
- segments:
82
- - 0
83
- hash: 1988275936415246250
84
81
  required_rubygems_version: !ruby/object:Gem::Requirement
85
82
  none: false
86
83
  requirements:
87
84
  - - ! '>='
88
85
  - !ruby/object:Gem::Version
89
86
  version: '0'
90
- segments:
91
- - 0
92
- hash: 1988275936415246250
93
87
  requirements: []
94
88
  rubyforge_project: retriable
95
- rubygems_version: 1.8.24
89
+ rubygems_version: 1.8.25
96
90
  signing_key:
97
91
  specification_version: 3
98
92
  summary: Retriable is an simple DSL to retry a code block if an exception should be