with_retry 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +3 -0
- data/Gemfile +16 -0
- data/README.md +39 -0
- data/Rakefile +5 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/core_ext/kernel.rb +16 -0
- data/lib/with_retry.rb +3 -0
- data/lib/with_retry/functions.rb +20 -0
- data/lib/with_retry/version.rb +3 -0
- data/with_retry.gemspec +21 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 68cdc6fa28609c1bcad3abce5f83fc39c9fded4b
|
4
|
+
data.tar.gz: cdf6628960c02f5ae8557f1588a1e643c4f1ad8a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 800262ab0588a686d68d66e8fbbce3bdc95099bff3a1001dcb02ce577318cc2c5adfad9389984eb95f6c4bf46cd61460a961cf43e80c29feb634bc5f406cf3c3
|
7
|
+
data.tar.gz: d8d21bb2d881b4c51c6519d0d8e671533568e5a7f99f0c2de7b5592df24455ce4269f4bdb45655f57127e3bbf1ebf11b88c557c8b48d10f0041a98ef8c171b60
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
group :development, :test do
|
4
|
+
gem 'pry'
|
5
|
+
gem 'pry-doc'
|
6
|
+
gem 'pry-byebug'
|
7
|
+
gem 'binding_of_caller'
|
8
|
+
gem 'awesome_print'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "minitest"
|
13
|
+
gem "minitest-power_assert"
|
14
|
+
end
|
15
|
+
|
16
|
+
gemspec
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# WithRetry
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/with_retry`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'with_retry'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install with_retry
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/with_retry/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "with_retry"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Kernel
|
2
|
+
def with_retry(args = {})
|
3
|
+
count ||= 0
|
4
|
+
options ||= WithRetry::Functions.build_options(args)
|
5
|
+
yield
|
6
|
+
rescue options[:on]
|
7
|
+
if (count += 1) > options[:limit]
|
8
|
+
options[:before_giving_up].call
|
9
|
+
raise (options[:failed] || options[:on])
|
10
|
+
else
|
11
|
+
options[:before_retrying].call
|
12
|
+
sleep options[:sleep]
|
13
|
+
retry
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/with_retry.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module WithRetry
|
2
|
+
module Functions
|
3
|
+
def build_options(args = {})
|
4
|
+
defaults.merge(args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def defaults
|
8
|
+
{
|
9
|
+
limit: 3,
|
10
|
+
on: StandardError,
|
11
|
+
sleep: 0,
|
12
|
+
failed: nil,
|
13
|
+
before_giving_up: ->{},
|
14
|
+
before_retrying: ->{}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
module_function :build_options, :defaults
|
19
|
+
end
|
20
|
+
end
|
data/with_retry.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'with_retry/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "with_retry"
|
7
|
+
spec.version = WithRetry::VERSION
|
8
|
+
spec.authors = ["Tsukuru Tanimichi"]
|
9
|
+
spec.email = ["ttanimichi@hotmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Kernel#with_retry"
|
12
|
+
spec.homepage = "https://github.com/ttanimichi/with_retry"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
15
|
+
spec.bindir = "exe"
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: with_retry
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tsukuru Tanimichi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- ttanimichi@hotmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/core_ext/kernel.rb
|
56
|
+
- lib/with_retry.rb
|
57
|
+
- lib/with_retry/functions.rb
|
58
|
+
- lib/with_retry/version.rb
|
59
|
+
- with_retry.gemspec
|
60
|
+
homepage: https://github.com/ttanimichi/with_retry
|
61
|
+
licenses: []
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.5
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Kernel#with_retry
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|