tretry 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +7 -33
- data/lib/tretry/result.rb +22 -0
- data/lib/tretry.rb +22 -33
- metadata +14 -55
- data/.document +0 -5
- data/.rspec +0 -1
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -69
- data/LICENSE.txt +0 -20
- data/README.md +0 -43
- data/VERSION +0 -1
- data/shippable.yml +0 -9
- data/spec/spec_helper.rb +0 -15
- data/spec/tretry_spec.rb +0 -78
- data/tretry.gemspec +0 -62
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3f933d5081600c123053375007affe0de256d65786552eeed9f795df3db5a587
|
4
|
+
data.tar.gz: 97cb722fc297493e9e62df7f95aec8307f7d21904f56ec39d327426c200d8103
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d8a9a03e39478b6174012c927e9356f63c2728d9362747f0e3345ee0d5173047e30c317d0ae67e8a3c928203d3a0f4eceedad64433faf74a738dadf881263a2
|
7
|
+
data.tar.gz: a9af5b8ae687177475cf3aff52a6157dc8647676bc7519ccc01fadc98799166e12b6a5c030cf2f629ce2fee3bc08e7db58aedc9782783e16e95e9fea680c98c3
|
data/Rakefile
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'bundler'
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
5
3
|
begin
|
6
4
|
Bundler.setup(:default, :development)
|
7
5
|
rescue Bundler::BundlerError => e
|
@@ -9,41 +7,17 @@ rescue Bundler::BundlerError => e
|
|
9
7
|
$stderr.puts "Run `bundle install` to install missing gems"
|
10
8
|
exit e.status_code
|
11
9
|
end
|
12
|
-
require
|
13
|
-
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "tretry"
|
18
|
-
gem.homepage = "http://github.com/kaspernj/tretry"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{A library for doing retries in Ruby with timeouts, analysis of errors, waits between tries and more.}
|
21
|
-
gem.description = %Q{A library for doing retries in Ruby with timeouts, analysis of errors, waits between tries and more.}
|
22
|
-
gem.email = "k@spernj.org"
|
23
|
-
gem.authors = ["Kasper Johansen"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
10
|
+
require "rake"
|
27
11
|
|
28
|
-
require
|
29
|
-
require
|
12
|
+
require "rspec/core"
|
13
|
+
require "rspec/core/rake_task"
|
30
14
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
-
spec.pattern = FileList[
|
15
|
+
spec.pattern = FileList["spec/**/*_spec.rb"]
|
32
16
|
end
|
33
17
|
|
34
18
|
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
-
spec.pattern =
|
19
|
+
spec.pattern = "spec/**/*_spec.rb"
|
36
20
|
spec.rcov = true
|
37
21
|
end
|
38
22
|
|
39
23
|
task :default => :spec
|
40
|
-
|
41
|
-
require 'rdoc/task'
|
42
|
-
Rake::RDocTask.new do |rdoc|
|
43
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
-
|
45
|
-
rdoc.rdoc_dir = 'rdoc'
|
46
|
-
rdoc.title = "tretry #{version}"
|
47
|
-
rdoc.rdoc_files.include('README*')
|
48
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
-
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class Tretry::Result
|
2
|
+
attr_reader :error, :fails, :result
|
3
|
+
|
4
|
+
def initialize(error:, fails:, result:)
|
5
|
+
@error = error
|
6
|
+
@fails = fails
|
7
|
+
@result = result
|
8
|
+
end
|
9
|
+
|
10
|
+
def [](key)
|
11
|
+
case key
|
12
|
+
when :error
|
13
|
+
error
|
14
|
+
when :fails
|
15
|
+
fails
|
16
|
+
when :result
|
17
|
+
result
|
18
|
+
else
|
19
|
+
raise "Unknown key: #{key}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/tretry.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
#A library for doing retries in Ruby with timeouts, analysis of errors, waits between tries and more.
|
2
2
|
class Tretry
|
3
|
+
autoload :Result, "#{__dir__}/tretry/result"
|
4
|
+
|
3
5
|
attr_reader :fails
|
4
6
|
attr_accessor :timeout, :tries, :wait
|
5
7
|
|
6
|
-
#Valid keys that can be given as argument for the method 'try'.
|
7
|
-
VALID_KEYS = [:tries, :timeout, :wait, :interrupt, :exit, :errors, :return_error]
|
8
|
-
|
9
8
|
#===Runs a block of code a given amount of times until it succeeds.
|
10
9
|
#===Examples
|
11
10
|
# res = Tretry.try(:tries => 3) do
|
@@ -14,16 +13,20 @@ class Tretry
|
|
14
13
|
#
|
15
14
|
# puts "Tries: '#{res[:tries]}'."
|
16
15
|
# puts "Result: '#{res[:result}'."
|
17
|
-
def self.try(args
|
18
|
-
Tretry.new(args).try(&block)
|
16
|
+
def self.try(**args, &block)
|
17
|
+
Tretry.new(**args).try(&block)
|
19
18
|
end
|
20
19
|
|
21
|
-
def initialize(
|
22
|
-
@
|
20
|
+
def initialize(errors: nil, exit: true, interrupt: true, return_error: nil, timeout: nil, tries: 3, wait: nil)
|
21
|
+
@errors = errors
|
22
|
+
@exit = exit
|
23
23
|
@fails = []
|
24
|
+
@interrupt = interrupt
|
24
25
|
@before_retry = []
|
25
|
-
|
26
|
-
|
26
|
+
@return_error = return_error
|
27
|
+
@timeout = timeout
|
28
|
+
@tries = tries
|
29
|
+
@wait = wait
|
27
30
|
end
|
28
31
|
|
29
32
|
def before_retry(&block)
|
@@ -59,12 +62,12 @@ class Tretry
|
|
59
62
|
end
|
60
63
|
|
61
64
|
if @doraise
|
62
|
-
if @
|
65
|
+
if @return_error
|
63
66
|
@fails << {error: @error}
|
64
|
-
return
|
67
|
+
return Tretry::Result.new(
|
65
68
|
fails: @fails,
|
66
69
|
error: true
|
67
|
-
|
70
|
+
)
|
68
71
|
else
|
69
72
|
raise @error
|
70
73
|
end
|
@@ -75,29 +78,15 @@ class Tretry
|
|
75
78
|
break if @dobreak
|
76
79
|
end
|
77
80
|
|
78
|
-
|
81
|
+
Tretry::Result.new(
|
79
82
|
fails: @fails,
|
80
83
|
result: @res,
|
81
84
|
error: false
|
82
|
-
|
85
|
+
)
|
83
86
|
end
|
84
87
|
|
85
88
|
private
|
86
89
|
|
87
|
-
def parse_arguments
|
88
|
-
#Validate given arguments and set various variables.
|
89
|
-
raise "Expected argument to be a hash." unless @args.is_a?(Hash)
|
90
|
-
|
91
|
-
@args.each do |key, val|
|
92
|
-
raise "Invalid key: '#{key}'." unless VALID_KEYS.include?(key)
|
93
|
-
end
|
94
|
-
|
95
|
-
@args[:tries] ||= 3
|
96
|
-
@tries = @args[:tries].to_i
|
97
|
-
@wait = @args[:wait] ? @args[:wait] : nil
|
98
|
-
@timeout = @args[:timeout] ? @args[:timeout].to_f : nil
|
99
|
-
end
|
100
|
-
|
101
90
|
def try_with_timeout
|
102
91
|
begin
|
103
92
|
require "timeout"
|
@@ -112,13 +101,13 @@ private
|
|
112
101
|
|
113
102
|
def handle_error(e)
|
114
103
|
if e.class == Interrupt
|
115
|
-
raise e if
|
104
|
+
raise e if @interrupt
|
116
105
|
elsif e.class == SystemExit
|
117
|
-
raise e if
|
118
|
-
elsif last_try? ||
|
106
|
+
raise e if @exit
|
107
|
+
elsif last_try? || @errors&.include?(e.class)
|
119
108
|
@doraise = e
|
120
|
-
elsif @
|
121
|
-
#
|
109
|
+
elsif @errors&.include?(e.class)
|
110
|
+
# Given error was in the :errors-array - do nothing. Maybe later it should be logged and returned in a stats-hash or something? - knj
|
122
111
|
end
|
123
112
|
|
124
113
|
@error = e
|
metadata
CHANGED
@@ -1,93 +1,53 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tretry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Kasper
|
7
|
+
- Kasper Stöckel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: rspec
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 2.8.0
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 2.8.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rdoc
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.12'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.12'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: bundler
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
44
16
|
requirements:
|
45
|
-
- -
|
17
|
+
- - '='
|
46
18
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
19
|
+
version: 2.3.13
|
48
20
|
type: :development
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
|
-
- -
|
24
|
+
- - '='
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
26
|
+
version: 2.3.13
|
55
27
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
28
|
+
name: rspec
|
57
29
|
requirement: !ruby/object:Gem::Requirement
|
58
30
|
requirements:
|
59
|
-
- -
|
31
|
+
- - '='
|
60
32
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
33
|
+
version: 3.11.0
|
62
34
|
type: :development
|
63
35
|
prerelease: false
|
64
36
|
version_requirements: !ruby/object:Gem::Requirement
|
65
37
|
requirements:
|
66
|
-
- -
|
38
|
+
- - '='
|
67
39
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
40
|
+
version: 3.11.0
|
69
41
|
description: A library for doing retries in Ruby with timeouts, analysis of errors,
|
70
42
|
waits between tries and more.
|
71
43
|
email: k@spernj.org
|
72
44
|
executables: []
|
73
45
|
extensions: []
|
74
|
-
extra_rdoc_files:
|
75
|
-
- LICENSE.txt
|
76
|
-
- README.md
|
46
|
+
extra_rdoc_files: []
|
77
47
|
files:
|
78
|
-
- ".document"
|
79
|
-
- ".rspec"
|
80
|
-
- Gemfile
|
81
|
-
- Gemfile.lock
|
82
|
-
- LICENSE.txt
|
83
|
-
- README.md
|
84
48
|
- Rakefile
|
85
|
-
- VERSION
|
86
49
|
- lib/tretry.rb
|
87
|
-
-
|
88
|
-
- spec/spec_helper.rb
|
89
|
-
- spec/tretry_spec.rb
|
90
|
-
- tretry.gemspec
|
50
|
+
- lib/tretry/result.rb
|
91
51
|
homepage: http://github.com/kaspernj/tretry
|
92
52
|
licenses:
|
93
53
|
- MIT
|
@@ -107,8 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
67
|
- !ruby/object:Gem::Version
|
108
68
|
version: '0'
|
109
69
|
requirements: []
|
110
|
-
|
111
|
-
rubygems_version: 2.4.0
|
70
|
+
rubygems_version: 3.1.6
|
112
71
|
signing_key:
|
113
72
|
specification_version: 4
|
114
73
|
summary: A library for doing retries in Ruby with timeouts, analysis of errors, waits
|
data/.document
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
|
-
group :development do
|
9
|
-
gem "rspec", "~> 2.8.0"
|
10
|
-
gem "rdoc", "~> 3.12"
|
11
|
-
gem "bundler", ">= 1.0.0"
|
12
|
-
gem "jeweler", "~> 1.8.4"
|
13
|
-
end
|
14
|
-
|
15
|
-
gem "codeclimate-test-reporter", group: :test, require: nil
|
data/Gemfile.lock
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.3.6)
|
5
|
-
builder (3.2.2)
|
6
|
-
codeclimate-test-reporter (0.4.1)
|
7
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
8
|
-
diff-lcs (1.1.3)
|
9
|
-
docile (1.1.5)
|
10
|
-
faraday (0.8.9)
|
11
|
-
multipart-post (~> 1.2.0)
|
12
|
-
git (1.2.8)
|
13
|
-
github_api (0.10.1)
|
14
|
-
addressable
|
15
|
-
faraday (~> 0.8.1)
|
16
|
-
hashie (>= 1.2)
|
17
|
-
multi_json (~> 1.4)
|
18
|
-
nokogiri (~> 1.5.2)
|
19
|
-
oauth2
|
20
|
-
hashie (3.3.1)
|
21
|
-
highline (1.6.21)
|
22
|
-
jeweler (1.8.8)
|
23
|
-
builder
|
24
|
-
bundler (~> 1.0)
|
25
|
-
git (>= 1.2.5)
|
26
|
-
github_api (= 0.10.1)
|
27
|
-
highline (>= 1.6.15)
|
28
|
-
nokogiri (= 1.5.10)
|
29
|
-
rake
|
30
|
-
rdoc
|
31
|
-
json (1.8.1)
|
32
|
-
jwt (1.0.0)
|
33
|
-
multi_json (1.10.1)
|
34
|
-
multi_xml (0.5.5)
|
35
|
-
multipart-post (1.2.0)
|
36
|
-
nokogiri (1.5.10)
|
37
|
-
oauth2 (1.0.0)
|
38
|
-
faraday (>= 0.8, < 0.10)
|
39
|
-
jwt (~> 1.0)
|
40
|
-
multi_json (~> 1.3)
|
41
|
-
multi_xml (~> 0.5)
|
42
|
-
rack (~> 1.2)
|
43
|
-
rack (1.5.2)
|
44
|
-
rake (10.3.2)
|
45
|
-
rdoc (3.12.2)
|
46
|
-
json (~> 1.4)
|
47
|
-
rspec (2.8.0)
|
48
|
-
rspec-core (~> 2.8.0)
|
49
|
-
rspec-expectations (~> 2.8.0)
|
50
|
-
rspec-mocks (~> 2.8.0)
|
51
|
-
rspec-core (2.8.0)
|
52
|
-
rspec-expectations (2.8.0)
|
53
|
-
diff-lcs (~> 1.1.2)
|
54
|
-
rspec-mocks (2.8.0)
|
55
|
-
simplecov (0.9.1)
|
56
|
-
docile (~> 1.1.0)
|
57
|
-
multi_json (~> 1.0)
|
58
|
-
simplecov-html (~> 0.8.0)
|
59
|
-
simplecov-html (0.8.0)
|
60
|
-
|
61
|
-
PLATFORMS
|
62
|
-
ruby
|
63
|
-
|
64
|
-
DEPENDENCIES
|
65
|
-
bundler (>= 1.0.0)
|
66
|
-
codeclimate-test-reporter
|
67
|
-
jeweler (~> 1.8.4)
|
68
|
-
rdoc (~> 3.12)
|
69
|
-
rspec (~> 2.8.0)
|
data/LICENSE.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Kasper Johansen
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
[![Build Status](https://api.shippable.com/projects/540e7b9e3479c5ea8f9ec25b/badge?branchName=master)](https://app.shippable.com/projects/540e7b9e3479c5ea8f9ec25b/builds/latest)
|
2
|
-
[![Code Climate](https://codeclimate.com/github/kaspernj/tretry/badges/gpa.svg)](https://codeclimate.com/github/kaspernj/tretry)
|
3
|
-
[![Test Coverage](https://codeclimate.com/github/kaspernj/tretry/badges/coverage.svg)](https://codeclimate.com/github/kaspernj/tretry)
|
4
|
-
|
5
|
-
# tretry
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'tretry'
|
11
|
-
```
|
12
|
-
|
13
|
-
## Usage
|
14
|
-
|
15
|
-
### Simple retry three times (which is the default)
|
16
|
-
```ruby
|
17
|
-
Tretry.try do
|
18
|
-
# do something that might randomly fail.
|
19
|
-
end
|
20
|
-
```
|
21
|
-
|
22
|
-
### Retry with options
|
23
|
-
```ruby
|
24
|
-
Tretry.try(tries: 3, timeout: 1.5, errors: [SomeCustomError], wait: 1) do
|
25
|
-
# do something.
|
26
|
-
end
|
27
|
-
```
|
28
|
-
|
29
|
-
## Contributing to tretry
|
30
|
-
|
31
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
32
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
33
|
-
* Fork the project.
|
34
|
-
* Start a feature/bugfix branch.
|
35
|
-
* Commit and push until you are happy with your contribution.
|
36
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
37
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
38
|
-
|
39
|
-
## Copyright
|
40
|
-
|
41
|
-
Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
|
42
|
-
further details.
|
43
|
-
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.0.2
|
data/shippable.yml
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
require "codeclimate-test-reporter"
|
2
|
-
CodeClimate::TestReporter.start
|
3
|
-
|
4
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
5
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
-
require 'rspec'
|
7
|
-
require 'tretry'
|
8
|
-
|
9
|
-
# Requires supporting files with custom matchers and macros, etc,
|
10
|
-
# in ./support/ and its subdirectories.
|
11
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
-
|
13
|
-
RSpec.configure do |config|
|
14
|
-
|
15
|
-
end
|
data/spec/tretry_spec.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Tretry" do
|
4
|
-
context "#try" do
|
5
|
-
it "should be able to run blocks" do
|
6
|
-
try = 0
|
7
|
-
res = Tretry.try(tries: 5) do
|
8
|
-
try += 1
|
9
|
-
raise "Test #{try}" if try < 5
|
10
|
-
"kasper"
|
11
|
-
end
|
12
|
-
|
13
|
-
res[:error].should eq false
|
14
|
-
res[:result].should eq "kasper"
|
15
|
-
end
|
16
|
-
|
17
|
-
it "should be able to do waits between tries" do
|
18
|
-
try = 0
|
19
|
-
time_start = Time.now.to_f
|
20
|
-
res = Tretry.try(tries: 5, wait: 0.1) do
|
21
|
-
try += 1
|
22
|
-
raise "Test #{try}" if try < 5
|
23
|
-
"kasper"
|
24
|
-
end
|
25
|
-
|
26
|
-
time_end = Time.now.to_f
|
27
|
-
time_elap = time_end - time_start
|
28
|
-
time_elap.should > 0.4
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should be able to do timeouts with tries" do
|
32
|
-
try = 0
|
33
|
-
res = Tretry.try(tries: 5, timeout: 0.1) do
|
34
|
-
try += 1
|
35
|
-
sleep 0.5 if try < 5
|
36
|
-
"kasper"
|
37
|
-
end
|
38
|
-
|
39
|
-
res[:error].should eq false
|
40
|
-
res[:result].should eq "kasper"
|
41
|
-
res[:fails].length.should eq 4
|
42
|
-
|
43
|
-
res[:fails].each do |err|
|
44
|
-
err[:error].is_a?(Timeout::Error).should eq true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
it "#before_retry" do
|
50
|
-
before_retry_count = 0
|
51
|
-
try_count = 0
|
52
|
-
|
53
|
-
try = Tretry.new
|
54
|
-
|
55
|
-
try.before_retry do
|
56
|
-
before_retry_count += 1
|
57
|
-
end
|
58
|
-
|
59
|
-
try.try do
|
60
|
-
try_count += 1
|
61
|
-
raise "test" if try_count < 3
|
62
|
-
end
|
63
|
-
|
64
|
-
before_retry_count.should eq 2
|
65
|
-
|
66
|
-
try.fails.each do |try_i|
|
67
|
-
try_i[:error].is_a?(RuntimeError).should eq true
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should raise an error if fails" do
|
72
|
-
expect {
|
73
|
-
Tretry.try do
|
74
|
-
raise "fail"
|
75
|
-
end
|
76
|
-
}.to raise_error(RuntimeError)
|
77
|
-
end
|
78
|
-
end
|
data/tretry.gemspec
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: tretry 0.0.2 ruby lib
|
6
|
-
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.name = "tretry"
|
9
|
-
s.version = "0.0.2"
|
10
|
-
|
11
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
-
s.require_paths = ["lib"]
|
13
|
-
s.authors = ["Kasper Johansen"]
|
14
|
-
s.date = "2014-11-21"
|
15
|
-
s.description = "A library for doing retries in Ruby with timeouts, analysis of errors, waits between tries and more."
|
16
|
-
s.email = "k@spernj.org"
|
17
|
-
s.extra_rdoc_files = [
|
18
|
-
"LICENSE.txt",
|
19
|
-
"README.md"
|
20
|
-
]
|
21
|
-
s.files = [
|
22
|
-
".document",
|
23
|
-
".rspec",
|
24
|
-
"Gemfile",
|
25
|
-
"Gemfile.lock",
|
26
|
-
"LICENSE.txt",
|
27
|
-
"README.md",
|
28
|
-
"Rakefile",
|
29
|
-
"VERSION",
|
30
|
-
"lib/tretry.rb",
|
31
|
-
"shippable.yml",
|
32
|
-
"spec/spec_helper.rb",
|
33
|
-
"spec/tretry_spec.rb",
|
34
|
-
"tretry.gemspec"
|
35
|
-
]
|
36
|
-
s.homepage = "http://github.com/kaspernj/tretry"
|
37
|
-
s.licenses = ["MIT"]
|
38
|
-
s.rubygems_version = "2.4.0"
|
39
|
-
s.summary = "A library for doing retries in Ruby with timeouts, analysis of errors, waits between tries and more."
|
40
|
-
|
41
|
-
if s.respond_to? :specification_version then
|
42
|
-
s.specification_version = 4
|
43
|
-
|
44
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
46
|
-
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
-
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
48
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
51
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
53
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
54
|
-
end
|
55
|
-
else
|
56
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
57
|
-
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
-
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
59
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|