retriable 2.1.0 → 3.0.0

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: 56415871220fd82fcfd72e2748a5a8283072bfa9
4
- data.tar.gz: 93dfae047c70da13dc9b9a64331d1b1e62273ced
3
+ metadata.gz: caa61297a00e84eb47ae1cb5ba47e5c6c7c1ac15
4
+ data.tar.gz: 58ae81f587962572385c25a174c937ab64498108
5
5
  SHA512:
6
- metadata.gz: 42de39c02026a18aa580bac6186038460f1d83a48681b703da8fbe40bb1bcdd5a6f4e06d9cbc9daf5e2129d1e9f32c0cb05ce1f153de721e07341ed0f00dbb8c
7
- data.tar.gz: 42dd35b52204d819e1b1d0c31eaadc5eef643b8a1daf69e694e29aff900d7995aa159ec2060bf4d414f66ffb2e5b6fd458ec2574a61d4192064cb0fc802a43e1
6
+ metadata.gz: a46713eaf3682dff2cab88edae795817fba5087edb2d79092d8d9c70b7db74376a0b57cf7fcae425c7862d835459ebce48421294b1f0347cc673c742d8343b52
7
+ data.tar.gz: b7ab15c4766136e3136a8b48686d6709439987d31b369dd04802e236def0b463f02f3a95d73f010fcba0e129bc14c36010e513c0ec8f01f3930acf63d4a71654
@@ -3,21 +3,22 @@
3
3
  sudo: false
4
4
  language: ruby
5
5
  rvm:
6
- - 1.9.3
7
6
  - 2.0.0
8
- - 2.1.7
9
- - 2.2.3
7
+ - 2.1.10
8
+ - 2.2.6
9
+ - 2.3.3
10
+ - 2.4.0
10
11
  - rbx
11
- - jruby-9.0.0.0
12
+ - jruby-9.0.5.0
13
+ - jruby-9.1.6.0
12
14
  - ruby-head
13
15
  - jruby-head
14
16
 
15
17
  matrix:
16
18
  allow_failures:
17
- - rvm: 1.9.3
19
+ - rvm: rbs
18
20
  - rvm: ruby-head
19
21
  - rvm: jruby-head
20
- - rvm: jruby-9.0.0.0
21
22
 
22
23
  addons:
23
24
  code_climate:
@@ -1,5 +1,10 @@
1
1
  ## HEAD
2
2
 
3
+ ## 3.0.0
4
+ * Require ruby 2.0+.
5
+ * Breaking Change: `on` with a `Hash` value now matches subclassed exceptions. Thanks @apurvis!
6
+ * Remove `awesome_print` from development environment.
7
+
3
8
  ## 2.1.0
4
9
 
5
10
  * Fix bug #17 due to confusing the initial try as a retry.
data/Gemfile CHANGED
@@ -12,5 +12,4 @@ end
12
12
 
13
13
  group :development, :test do
14
14
  gem "pry"
15
- gem "awesome_print"
16
15
  end
data/README.md CHANGED
@@ -4,17 +4,15 @@
4
4
  [![Code Climate](https://codeclimate.com/github/kamui/retriable/badges/gpa.svg)](https://codeclimate.com/github/kamui/retriable)
5
5
  [![Test Coverage](https://codeclimate.com/github/kamui/retriable/badges/coverage.svg)](https://codeclimate.com/github/kamui/retriable)
6
6
 
7
- Retriable is an simple DSL to retry failed code blocks with randomized [exponential backoff](http://en.wikipedia.org/wiki/Exponential_backoff) time intervals. This is especially useful when interacting external api/services or file system calls.
7
+ Retriable is a simple DSL to retry failed code blocks with randomized [exponential backoff](http://en.wikipedia.org/wiki/Exponential_backoff) time intervals. This is especially useful when interacting external api/services or file system calls.
8
8
 
9
9
  ## Requirements
10
10
 
11
- Ruby 1.9.3+
11
+ Ruby 2.0.0+
12
12
 
13
- If you need ruby 1.8.x to 1.9.2 support, use the [1.x branch](https://github.com/kamui/retriable/tree/1.x).
13
+ If you need ruby 1.9.3 support, use the [2.x branch](https://github.com/kamui/retriable/tree/2.x) by specifying `~2.1` in your Gemfile.
14
14
 
15
- There's a [1.x to 2.x migration wiki entry](https://github.com/kamui/retriable/wiki/Migrating-to-2.x) available.
16
-
17
- WARNING: 2.x isn't API compatible with 1.x.
15
+ If you need ruby 1.8.x to 1.9.2 support, use the [1.x branch](https://github.com/kamui/retriable/tree/1.x) by specifying `~1.4` in your Gemfile.
18
16
 
19
17
  ## Installation
20
18
 
@@ -33,7 +31,7 @@ require 'retriable'
33
31
  In your Gemfile:
34
32
 
35
33
  ```ruby
36
- gem 'retriable', '~> 2.0'
34
+ gem 'retriable', '~> 3.0'
37
35
  ```
38
36
 
39
37
  ## Usage
@@ -90,7 +88,7 @@ randomized_interval = retry_interval * (random value in range [1 - randomization
90
88
 
91
89
  `timeout` (default: nil) - Number of seconds to allow the code block to run before raising a `Timeout::Error` inside each try. Default is `nil` means the code block can run forever without raising error.
92
90
 
93
- `on` (default: [StandardError]) - An `Array` of exceptions to rescue for each try, a `Hash` where the keys are `Exception` classes and the values can be a single `Regexp` pattern or a list of patterns, or a single `Exception` type.
91
+ `on` (default: [StandardError]) - An `Array` of exceptions to rescue for each try, a `Hash` where the keys are `Exception` classes and the values can be a single `Regexp` pattern or a list of patterns, or a single `Exception` type. Subclasses of the listed exceptions will be retried and have their messages matched in the same way.
94
92
 
95
93
  `on_retry` - (default: nil) - Proc to call after each try is rescued.
96
94
 
@@ -135,7 +133,7 @@ Retriable.retriable on: {
135
133
  end
136
134
  ```
137
135
 
138
- You can also specify a timeout if you want the code block to only make an try for X amount of seconds. This timeout is per try.
136
+ You can also specify a timeout if you want the code block to only try for X amount of seconds. This timeout is per try.
139
137
 
140
138
  ```ruby
141
139
  Retriable.retriable timeout: 60 do
@@ -199,7 +197,7 @@ end
199
197
 
200
198
  ```ruby
201
199
  do_this_on_each_retry = Proc.new do |exception, try, elapsed_time, next_interval|
202
- log "#{exception.class}: '#{exception.message}' - #{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try."}
200
+ log "#{exception.class}: '#{exception.message}' - #{try} tries in #{elapsed_time} seconds and #{next_interval} seconds until the next try."
203
201
  end
204
202
 
205
203
  Retriable.retriable on_retry: do_this_on_each_retry do
@@ -55,14 +55,11 @@ module Retriable
55
55
  end
56
56
  rescue *[*exception_list] => exception
57
57
  if on.kind_of?(Hash)
58
- patterns = [*on[exception.class]]
59
- message_match = patterns.empty? ? true : false
60
- patterns.each do |pattern|
61
- if !!(exception.message =~ pattern)
62
- message_match = true
63
- break
64
- end
58
+ message_match = exception_list.select { |e| exception.is_a?(e) }.inject(false) do |match, e|
59
+ break match if match
60
+ match || [*on[e]].empty? || [*on[e]].any? { |pattern| exception.message =~ pattern }
65
61
  end
62
+
66
63
  raise unless message_match
67
64
  end
68
65
 
@@ -1,3 +1,3 @@
1
1
  module Retriable
2
- VERSION = "2.1.0"
2
+ VERSION = "3.0.0"
3
3
  end
@@ -19,12 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.required_ruby_version = '>= 1.9.3'
22
+ spec.required_ruby_version = '>= 2.0.0'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "rake", "~> 10.4"
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 12.0"
26
26
 
27
- spec.add_development_dependency "minitest", "~> 5.6"
27
+ spec.add_development_dependency "minitest", "~> 5.10"
28
28
  spec.add_development_dependency "guard"
29
29
  spec.add_development_dependency "guard-minitest"
30
+ spec.add_development_dependency "listen", "~> 3.1"
30
31
  end
@@ -250,6 +250,35 @@ describe Retriable do
250
250
  expect(e.message).must_equal "something went wrong"
251
251
  end
252
252
 
253
+ it "#retriable with a hash exception list matches exception subclasses" do
254
+ class SecondTestError < TestError; end
255
+
256
+ tries = 0
257
+ e = expect do
258
+ subject.retriable on: { TestError => /something went wrong/ }, tries: 4 do
259
+ tries += 1
260
+ raise SecondTestError.new('something went wrong')
261
+ end
262
+ end.must_raise SecondTestError
263
+
264
+ expect(e.message).must_equal "something went wrong"
265
+ expect(tries).must_equal 4
266
+ end
267
+
268
+ it "#retriable with a hash exception list does not retry matching exception subclass but not message" do
269
+ class SecondTestError < TestError; end
270
+
271
+ tries = 0
272
+ e = expect do
273
+ subject.retriable on: { TestError => /something went wrong/ }, tries: 4 do
274
+ tries += 1
275
+ raise SecondTestError.new('not a match')
276
+ end
277
+ end.must_raise SecondTestError
278
+
279
+ expect(tries).must_equal 1
280
+ end
281
+
253
282
  it "#retriable with a hash exception list where the values are exception message patterns" do
254
283
  tries = 0
255
284
  exceptions = []
@@ -5,17 +5,10 @@ CodeClimate::TestReporter.configure do |config|
5
5
  config.logger.level = Logger::WARN
6
6
  end
7
7
 
8
- SimpleCov.start do
9
- formatter SimpleCov::Formatter::MultiFormatter[
10
- SimpleCov::Formatter::HTMLFormatter,
11
- CodeClimate::TestReporter::Formatter
12
- ]
13
- add_filter 'spec/'
14
- end
8
+ SimpleCov.start
15
9
 
16
10
  require "minitest/autorun"
17
11
  require "minitest/focus"
18
- require "awesome_print"
19
12
  require "pry"
20
13
 
21
14
  require_relative "../lib/retriable"
@@ -7,7 +7,7 @@ build:
7
7
  steps:
8
8
  # Uncomment this to force RVM to use a specific Ruby version
9
9
  - rvm-use:
10
- version: 2.2.3
10
+ version: 2.3.1
11
11
 
12
12
  # A step that executes `bundle install` command
13
13
  - bundle-install
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retriable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Chu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-01 00:00:00.000000000 Z
11
+ date: 2017-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '1.13'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '1.13'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.4'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.4'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.6'
47
+ version: '5.10'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '5.6'
54
+ version: '5.10'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: guard
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,8 +80,25 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: |
84
- Retriable is an simple DSL to retry failed code blocks with randomized exponential backoff. This is especially useful when interacting external api/services or file system calls.
83
+ - !ruby/object:Gem::Dependency
84
+ name: listen
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ description: 'Retriable is an simple DSL to retry failed code blocks with randomized
98
+ exponential backoff. This is especially useful when interacting external api/services
99
+ or file system calls.
100
+
101
+ '
85
102
  email:
86
103
  - jack@jackchu.com
87
104
  executables: []
@@ -119,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
136
  requirements:
120
137
  - - ">="
121
138
  - !ruby/object:Gem::Version
122
- version: 1.9.3
139
+ version: 2.0.0
123
140
  required_rubygems_version: !ruby/object:Gem::Requirement
124
141
  requirements:
125
142
  - - ">="
@@ -127,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
144
  version: '0'
128
145
  requirements: []
129
146
  rubyforge_project:
130
- rubygems_version: 2.4.5.1
147
+ rubygems_version: 2.5.2
131
148
  signing_key:
132
149
  specification_version: 4
133
150
  summary: Retriable is an simple DSL to retry failed code blocks with randomized exponential