retryable-rb 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1 +1,3 @@
1
- v1.0.0. First release.
1
+ v1.1.0. Setting default retry sleep period to random.
2
+
3
+ v1.0.0. First release.
data/Manifest CHANGED
@@ -5,5 +5,4 @@ README.markdown
5
5
  Rakefile
6
6
  lib/retryable.rb
7
7
  retryable-rb.gemspec
8
- retryable.gemspec
9
8
  test/retryable_test.rb
@@ -6,7 +6,7 @@ Retryable is an easy to use DSL to retry code if an exception is raised. This i
6
6
  Installation
7
7
  ------------
8
8
 
9
- gem install retryable
9
+ gem install retryable-rb
10
10
 
11
11
  # In your ruby application
12
12
  require 'retryable'
@@ -28,7 +28,7 @@ Code wrapped in a Retryable block will be retried if a failure occurs. As such,
28
28
  end
29
29
  end
30
30
 
31
- By default, Retryable will rescue any exception inherited from `Exception`, retry once (for a total of two attempts) and sleep for 100 milliseconds. You can choose additional options by passing them via an options `Hash`.
31
+ By default, Retryable will rescue any exception inherited from `Exception`, retry once (for a total of two attempts) and sleep for a random amount time (between 0 to 100 milliseconds, in 10 millisecond increments). You can choose additional options by passing them via an options `Hash`.
32
32
 
33
33
  retryable :on => Timeout::Error, :times => 3, :sleep => 1 do
34
34
  # code here...
@@ -40,6 +40,12 @@ This example will only retry on a `Timeout::Error`, retry 3 times (for a total o
40
40
  # code here...
41
41
  end
42
42
 
43
+ You can also have Ruby retry immediately after a failure by passing `false` as the sleep option.
44
+
45
+ retryable :sleep => false do
46
+ # code here...
47
+ end
48
+
43
49
  Retryable also allows for callbacks to be defined, which is useful to log failures for analytics purposes or cleanup after repeated failures. Retryable has three types of callbacks: `then`, `finally`, and `always`.
44
50
 
45
51
  `then`: Run every time a failure occurs.
@@ -79,4 +85,4 @@ If you are using Retryable once or outside of a class, you can also use it via i
79
85
  Credits
80
86
  -------
81
87
 
82
- Retryable was inspired by code written by [Michael Celona](http://github.com/mcelona) and later assisted by [David Malin](http://github.com/dmalin).
88
+ Retryable was inspired by code written by [Michael Celona](http://github.com/mcelona) and later assisted by [David Malin](http://github.com/dmalin).
@@ -2,7 +2,7 @@ module Retryable
2
2
  extend self
3
3
 
4
4
  def retryable(options = {})
5
- opts = {:on => Exception, :times => 1, :sleep => 0.1}.merge(options)
5
+ opts = {:on => Exception, :times => 1}.merge(options)
6
6
  handler = {}
7
7
 
8
8
  retry_exception = opts[:on].is_a?(Array) ? opts[:on] : [opts[:on]]
@@ -17,7 +17,7 @@ module Retryable
17
17
  opts[:then].call(exception, handler, attempts, retries, times) if opts[:then]
18
18
 
19
19
  if attempts <= times
20
- sleep opts[:sleep]
20
+ sleep(opts[:sleep] || (rand(11) / 100.0)) unless opts[:sleep] == false
21
21
  retries -= 1
22
22
  retry
23
23
  else
@@ -30,4 +30,4 @@ module Retryable
30
30
 
31
31
  yield(handler)
32
32
  end
33
- end
33
+ end
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{retryable-rb}
5
- s.version = "1.0.0"
5
+ s.version = "1.1.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Robert Sosinski"]
9
- s.date = %q{2011-04-12}
9
+ s.date = %q{2011-04-17}
10
10
  s.description = %q{Easy to use DSL to retry code if an exception is raised.}
11
11
  s.email = %q{email@robertsosinski.com}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.markdown", "lib/retryable.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/retryable.rb", "retryable-rb.gemspec", "retryable.gemspec", "test/retryable_test.rb"]
13
+ s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/retryable.rb", "retryable-rb.gemspec", "test/retryable_test.rb"]
14
14
  s.homepage = %q{http://github.com/robertsosinski/retryable}
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Retryable-rb", "--main", "README.markdown"]
16
16
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retryable-rb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Sosinski
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-12 00:00:00 -04:00
18
+ date: 2011-04-17 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -53,7 +53,6 @@ files:
53
53
  - Rakefile
54
54
  - lib/retryable.rb
55
55
  - retryable-rb.gemspec
56
- - retryable.gemspec
57
56
  - test/retryable_test.rb
58
57
  has_rdoc: true
59
58
  homepage: http://github.com/robertsosinski/retryable
@@ -1,34 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{retryable}
5
- s.version = "1.0.0"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Robert Sosinski"]
9
- s.date = %q{2011-04-11}
10
- s.description = %q{Easy to use DSL to retry code if an exception is raised.}
11
- s.email = %q{email@robertsosinski.com}
12
- s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README.markdown", "lib/retryable.rb"]
13
- s.files = ["CHANGELOG", "LICENSE", "Manifest", "README.markdown", "Rakefile", "lib/retryable.rb", "retryable.gemspec", "test/retryable_test.rb"]
14
- s.homepage = %q{http://github.com/robertsosinski/retryable}
15
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Retryable", "--main", "README.markdown"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = %q{retryable}
18
- s.rubygems_version = %q{1.3.7}
19
- s.summary = %q{Easy to use DSL to retry code if an exception is raised.}
20
- s.test_files = ["test/retryable_test.rb"]
21
-
22
- if s.respond_to? :specification_version then
23
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
- s.specification_version = 3
25
-
26
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
27
- s.add_development_dependency(%q<echoe>, [">= 4.3.1"])
28
- else
29
- s.add_dependency(%q<echoe>, [">= 4.3.1"])
30
- end
31
- else
32
- s.add_dependency(%q<echoe>, [">= 4.3.1"])
33
- end
34
- end