retryable 1.3.4 → 1.3.5

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
  SHA1:
3
- metadata.gz: 5e881ef13cb134d2b9e52b3c478e1d1d02e85898
4
- data.tar.gz: 76d3a74f41fc44a60d06054760d36206df77304a
3
+ metadata.gz: 5cc19b6b707fdd02171896378738cffa3c063cc6
4
+ data.tar.gz: 70efcfedc8895f963c166ed19374653521fb271a
5
5
  SHA512:
6
- metadata.gz: b5e65752232a6ddcefb4e46d8cf3908eda78db9f8ff40d91f9464d37f7ae98f8585bf90c73b72e326915dcf4cedd2e70cc97e89b33908948491dd736546a9fb6
7
- data.tar.gz: 2d1fcbfcc5206dd347aba24a5cdb5c7734881b75080232ad729e53dbf0a7118223176355083ed8d59aea814090065e249fe59bd39b6c72a5ce076bcf7f2afd42
6
+ metadata.gz: a302e5df64a1923ef5166f01c3d9ca1e70ee76b07ff50ebe03b51e99d1fb7ce9054aa93cb7e84096fedf7f7d38fbf9866873b6354c6fef5a51457cedf00448e3
7
+ data.tar.gz: d59b938aad7314d2ea885e86945642393ad4f11ce3f80b0fedbb22c120593fef03fe1acdbc81dabef9324b77afa4cc2f1922b4bbf0e0630b892de5514d19e215
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## Retryable 1.3.5 ##
2
+
3
+ * New callback option(:exception_cb) to run after an rescued exception is introduced. Thanks @jondruse
4
+
1
5
  ## Retryable 1.3.4 ##
2
6
 
3
7
  * Namespace issue has been fixed. Thanks @darkhelmet
data/README.md CHANGED
@@ -9,7 +9,7 @@ Description
9
9
  Runs a code block, and retries it when an exception occurs. It's great when
10
10
  working with flakey webservices (for example).
11
11
 
12
- It's configured using four optional parameters `:tries`, `:on`, `:sleep`, `:matching`, `:ensure` and
12
+ It's configured using four optional parameters `:tries`, `:on`, `:sleep`, `:matching`, `:ensure`, `:exception_cb` and
13
13
  runs the passed block. Should an exception occur, it'll retry for (n-1) times.
14
14
 
15
15
  Should the number of retries be reached without success, the last exception
@@ -56,7 +56,7 @@ end
56
56
 
57
57
  ## Defaults
58
58
 
59
- :tries => 2, :on => StandardError, :sleep => 1, :matching => /.*/, :ensure => Proc.new { }
59
+ :tries => 2, :on => StandardError, :sleep => 1, :matching => /.*/, :ensure => Proc.new { }, :exception_cb => Proc.new { }
60
60
 
61
61
  Sleeping
62
62
  --------
@@ -89,6 +89,17 @@ retryable do |retries, exception|
89
89
  end
90
90
  ```
91
91
 
92
+ Callback to run after an exception is rescued
93
+ --------
94
+ exception_cb = Proc.new do |exception|
95
+ ExceptionNotifier.notify_exception(exception, :data => {:message => "it failed"}) # http://smartinez87.github.io/exception_notification
96
+ end
97
+
98
+ retryable(:exception_cb => exception_cb) do
99
+ # perform risky operation
100
+ end
101
+
102
+
92
103
  You can temporary disable retryable blocks
93
104
  --------
94
105
 
data/lib/retryable.rb CHANGED
@@ -3,7 +3,7 @@ require 'retryable/config'
3
3
 
4
4
  module Kernel
5
5
  def retryable(options = {}, &block)
6
- opts = {:tries => 2, :sleep => 1, :on => StandardError, :matching => /.*/, :ensure => Proc.new {}}
6
+ opts = {:tries => 2, :sleep => 1, :on => StandardError, :matching => /.*/, :ensure => Proc.new {}, :exception_cb => Proc.new {}}
7
7
  check_for_invalid_options(options, opts)
8
8
  opts.merge!(options)
9
9
 
@@ -28,6 +28,7 @@ module Kernel
28
28
 
29
29
  retries += 1
30
30
  retry_exception = exception
31
+ opts[:exception_cb].call(retry_exception)
31
32
  retry
32
33
  ensure
33
34
  opts[:ensure].call(retries)
@@ -2,7 +2,7 @@ module Retryable
2
2
  class Version
3
3
  MAJOR = 1 unless defined? Retryable::Version::MAJOR
4
4
  MINOR = 3 unless defined? Retryable::Version::MINOR
5
- PATCH = 4 unless defined? Retryable::Version::PATCH
5
+ PATCH = 5 unless defined? Retryable::Version::PATCH
6
6
 
7
7
  class << self
8
8
 
@@ -107,4 +107,12 @@ describe 'Kernel.retryable' do
107
107
  retryable(:bad_option => 2) { raise "this is bad" }
108
108
  end.should raise_error ArgumentError, '[Retryable] Invalid options: bad_option'
109
109
  end
110
+
111
+ it 'accepts a callback to run after an exception is rescued' do
112
+ lambda do
113
+ retryable(:sleep => 0, :exception_cb => Proc.new {|e| @raised = e.to_s }) {|tries, ex| raise StandardError.new("this is fun!") if tries < 1 }
114
+ end.should_not raise_error
115
+
116
+ @raised.should == "this is fun!"
117
+ end
110
118
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retryable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Fedyashev
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-03 00:00:00.000000000 Z
13
+ date: 2014-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler