easy_retry 1.0.0 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +3 -0
- data/.rubocop.yml +14 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +72 -0
- data/LICENSE.txt +21 -0
- data/README.md +90 -0
- data/Rakefile +12 -0
- data/lib/easy_retry/version.rb +5 -0
- data/lib/easy_retry.rb +20 -6
- data/sig/easy_retry.rbs +4 -0
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c38067f87c684be6a9f709ec44bd993a6ac511998f0c946747143256d88fbe7c
|
4
|
+
data.tar.gz: a2ffb08ccca6d6a9abea4b4ba962b1fad80f356ec848e468523240edea2cf56c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd8bd03df3327dc40e163bdb594e06e1b5d35da04ec569699a5ded179515ab7e1e2757ab2e204d3bcaa53dff77601dc0924fee4e9e40b195c495f07dd91c9ae1
|
7
|
+
data.tar.gz: fcaae7e8ddfa04c0e58e7511e751feb67c699300b77d1cd52d5f94c3fae18fe872e1b10543d54480ecfe380cbcceb8f20eb708f53b700ee5b32bf8ac78d0b7ef
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
TargetRubyVersion: 2.6.0
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at r.goudeketting@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in easy_retry.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
|
14
|
+
gem "pry"
|
15
|
+
|
16
|
+
gem "simplecov", require: false
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
easy_retry (1.0.4)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
coderay (1.1.3)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
docile (1.4.0)
|
13
|
+
json (2.6.2)
|
14
|
+
method_source (1.0.0)
|
15
|
+
parallel (1.22.1)
|
16
|
+
parser (3.1.2.1)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
pry (0.14.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
rainbow (3.1.1)
|
22
|
+
rake (13.0.6)
|
23
|
+
regexp_parser (2.6.1)
|
24
|
+
rexml (3.2.5)
|
25
|
+
rspec (3.12.0)
|
26
|
+
rspec-core (~> 3.12.0)
|
27
|
+
rspec-expectations (~> 3.12.0)
|
28
|
+
rspec-mocks (~> 3.12.0)
|
29
|
+
rspec-core (3.12.0)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-expectations (3.12.0)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-mocks (3.12.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-support (3.12.0)
|
38
|
+
rubocop (1.39.0)
|
39
|
+
json (~> 2.3)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 3.1.2.1)
|
42
|
+
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.8, < 3.0)
|
44
|
+
rexml (>= 3.2.5, < 4.0)
|
45
|
+
rubocop-ast (>= 1.23.0, < 2.0)
|
46
|
+
ruby-progressbar (~> 1.7)
|
47
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
+
rubocop-ast (1.23.0)
|
49
|
+
parser (>= 3.1.1.0)
|
50
|
+
ruby-progressbar (1.11.0)
|
51
|
+
simplecov (0.21.2)
|
52
|
+
docile (~> 1.1)
|
53
|
+
simplecov-html (~> 0.11)
|
54
|
+
simplecov_json_formatter (~> 0.1)
|
55
|
+
simplecov-html (0.12.3)
|
56
|
+
simplecov_json_formatter (0.1.4)
|
57
|
+
unicode-display_width (2.3.0)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
x86_64-darwin-21
|
61
|
+
x86_64-linux
|
62
|
+
|
63
|
+
DEPENDENCIES
|
64
|
+
easy_retry!
|
65
|
+
pry
|
66
|
+
rake (~> 13.0)
|
67
|
+
rspec (~> 3.0)
|
68
|
+
rubocop (~> 1.21)
|
69
|
+
simplecov
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.3.7
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 GoudekettingRM
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
![Specs](https://github.com/goudekettingrm/easy_retry/actions/workflows/main.yml/badge.svg)
|
2
|
+
|
3
|
+
# EasyRetry
|
4
|
+
|
5
|
+
<i>Easily retry a block of code a predetermined number of times.</i>
|
6
|
+
|
7
|
+
Easy Retry adds a #tries method to the Numeric class. The #tries method takes a block of code and will retry the block a number of times equal to the number the method is called on. It also aliases #try to #tries in the odd case that you want to (~re~?)try a block of code only once.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'easy_retry'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install easy_retry
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
If you're not using Bundler, you'll need to require the gem in your code:
|
28
|
+
```rb
|
29
|
+
require 'easy_retry'
|
30
|
+
```
|
31
|
+
|
32
|
+
### Basic Example
|
33
|
+
|
34
|
+
```rb
|
35
|
+
4.tries do |try|
|
36
|
+
raise 'Something went wrong' if try < 4
|
37
|
+
puts "Success!"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
The code above will produce the following output:
|
42
|
+
|
43
|
+
```
|
44
|
+
Error: Something went wrong (1/4)
|
45
|
+
Error: Something went wrong (2/4)
|
46
|
+
Error: Something went wrong (3/4)
|
47
|
+
Success!
|
48
|
+
```
|
49
|
+
|
50
|
+
## Only Retry on Certain Exceptions
|
51
|
+
|
52
|
+
Sometimes you want to only retry your code if a specific exception is raised. You can do this by passing a list of exceptions to the #tries method:
|
53
|
+
|
54
|
+
```rb
|
55
|
+
4.tries(rescue_from: [ZeroDivisionError, ArgumentError]) do |try|
|
56
|
+
raise ZeroDivisionError if try < 2
|
57
|
+
raise ActiveRecord::RecordInvalid if try < 4
|
58
|
+
puts "Success!"
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
The code above will not rescue from the `ActiveRecord::RecordInvalid` error and produce the following output:
|
63
|
+
|
64
|
+
```
|
65
|
+
Error: ZeroDivisionError (1/4)
|
66
|
+
ActiveRecord::RecordInvalid: Record invalid
|
67
|
+
from (pry):16:in `block in __pry__'
|
68
|
+
```
|
69
|
+
|
70
|
+
## Retry delay
|
71
|
+
|
72
|
+
The delay for each retry is based on the iteration count. The delay after each failed attempt is _n^2_, where _n_ is the current iteration that failed. E.g. after the first try, EasyRetry waits 1 second, after the second try it waits 4 seconds, then 9, then 16, then 25, then 36, etc.
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
77
|
+
|
78
|
+
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`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
79
|
+
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/easy_retry. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/easy_retry/blob/main/CODE_OF_CONDUCT.md).
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
87
|
+
|
88
|
+
## Code of Conduct
|
89
|
+
|
90
|
+
Everyone interacting in the EasyRetry project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/easy_retry/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/lib/easy_retry.rb
CHANGED
@@ -1,24 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "easy_retry/version"
|
4
|
+
|
5
|
+
# Extend the Numeric class with a #tries method
|
1
6
|
class Numeric
|
7
|
+
# rubocop:disable Metrics/MethodLength
|
2
8
|
def tries(rescue_from: [StandardError])
|
3
|
-
raise ArgumentError,
|
9
|
+
raise ArgumentError, "No block given" unless block_given?
|
4
10
|
|
5
11
|
max_retry = self
|
6
12
|
current_try = 1
|
13
|
+
result = nil
|
7
14
|
|
8
15
|
loop do
|
9
|
-
yield(current_try)
|
16
|
+
result = yield(current_try)
|
10
17
|
|
11
18
|
break
|
12
|
-
rescue *rescue_from =>
|
13
|
-
|
19
|
+
rescue *rescue_from => e
|
20
|
+
if defined?(Rails)
|
21
|
+
Rails.logger.error "Error: #{e.message} (#{current_try}/#{max_retry})"
|
22
|
+
else
|
23
|
+
puts "Error: #{e.message} (#{current_try}/#{max_retry})"
|
24
|
+
end
|
14
25
|
|
15
|
-
sleep
|
26
|
+
sleep current_try * current_try
|
16
27
|
|
17
28
|
current_try += 1
|
18
29
|
|
19
|
-
raise
|
30
|
+
raise e if current_try > max_retry
|
20
31
|
end
|
32
|
+
|
33
|
+
result
|
21
34
|
end
|
35
|
+
# rubocop:enable Metrics/MethodLength
|
22
36
|
|
23
37
|
alias try tries
|
24
38
|
end
|
data/sig/easy_retry.rbs
ADDED
metadata
CHANGED
@@ -1,28 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_retry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Robin Goudeketting
|
8
|
-
- Peter Duijnstee
|
7
|
+
- Robin Goudeketting, Peter Duijnstee
|
9
8
|
autorequire:
|
10
|
-
bindir:
|
9
|
+
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-17 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: Easily retry a block of code a predetermined number of times
|
15
14
|
email:
|
16
|
-
-
|
15
|
+
- robin@goudeketting.nl
|
17
16
|
executables: []
|
18
17
|
extensions: []
|
19
18
|
extra_rdoc_files: []
|
20
19
|
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- CODE_OF_CONDUCT.md
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
21
29
|
- lib/easy_retry.rb
|
22
|
-
|
30
|
+
- lib/easy_retry/version.rb
|
31
|
+
- sig/easy_retry.rbs
|
32
|
+
homepage: https://github.com/GoudekettingRM/easy_retry
|
23
33
|
licenses:
|
24
34
|
- MIT
|
25
|
-
metadata:
|
35
|
+
metadata:
|
36
|
+
homepage_uri: https://github.com/GoudekettingRM/easy_retry
|
37
|
+
source_code_uri: https://github.com/GoudekettingRM/easy_retry
|
38
|
+
changelog_uri: https://github.com/GoudekettingRM/easy_retry/blob/main/CHANGELOG.md
|
39
|
+
rubygems_mfa_required: 'true'
|
26
40
|
post_install_message:
|
27
41
|
rdoc_options: []
|
28
42
|
require_paths:
|
@@ -31,14 +45,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
45
|
requirements:
|
32
46
|
- - ">="
|
33
47
|
- !ruby/object:Gem::Version
|
34
|
-
version:
|
48
|
+
version: 2.6.0
|
35
49
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
50
|
requirements:
|
37
51
|
- - ">="
|
38
52
|
- !ruby/object:Gem::Version
|
39
53
|
version: '0'
|
40
54
|
requirements: []
|
41
|
-
rubygems_version: 3.
|
55
|
+
rubygems_version: 3.3.7
|
42
56
|
signing_key:
|
43
57
|
specification_version: 4
|
44
58
|
summary: Easily retry a block of code a predetermined number of times
|