retry_on_error 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d9efeb9e1c5e971b006e600b5998a48b6a8833fc1c1705930951236e757c7214
4
+ data.tar.gz: 705af84f35b4c3cdc0b88b8aead5a9680f68445a401697dd9cd745993deafe80
5
+ SHA512:
6
+ metadata.gz: ce056c2b58db144b6a3ff30eaab5d8af527ccca9c03c8bc928b93e0fe7d9d8307de27f92d29be0df559674872e6015d164bda581cd16cc06ffc9679308b06f36
7
+ data.tar.gz: 18c7262a8cddf97264dc917499283ce3bd4c697094e491a7803fe8f564bb33e8d6c22ef5372df58fb05aa90b5c2b8bc77d818fdf019e4230f1de396a63a81c9c
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,77 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ Include:
4
+ - 'lib/**/*'
5
+ - 'spec/**/*'
6
+
7
+ Layout/LineLength:
8
+ Max: 120
9
+
10
+ Layout/SpaceBeforeBlockBraces:
11
+ EnforcedStyle: space
12
+
13
+ Layout/SpaceInsideArrayLiteralBrackets:
14
+ Enabled: false
15
+
16
+ Layout/SpaceInsideParens:
17
+ Enabled: false
18
+
19
+ Lint/DuplicateRegexpCharacterClassElement:
20
+ Enabled: true
21
+
22
+ Lint/EmptyBlock:
23
+ Enabled: false
24
+
25
+ Lint/MissingSuper:
26
+ Enabled: false
27
+
28
+ Lint/NoReturnInBeginEndBlocks:
29
+ Enabled: true
30
+
31
+ Lint/ToEnumArguments:
32
+ Enabled: true
33
+
34
+ Lint/UnmodifiedReduceAccumulator:
35
+ Enabled: true
36
+
37
+ Metrics/BlockLength:
38
+ Enabled: false
39
+
40
+ Metrics/MethodLength:
41
+ Enabled: false
42
+
43
+ Style/ArgumentsForwarding:
44
+ Enabled: false # enable when Ruby 2.7 is min. supported version
45
+
46
+ Style/BlockDelimiters:
47
+ Enabled: false
48
+
49
+ Style/CollectionCompact:
50
+ Enabled: true
51
+
52
+ Style/Documentation:
53
+ Enabled: false
54
+
55
+ Style/DocumentDynamicEvalDefinition:
56
+ Enabled: true
57
+
58
+ Style/ExpandPathArguments:
59
+ Enabled: false
60
+
61
+ Style/Lambda:
62
+ Enabled: false
63
+
64
+ Style/MutableConstant:
65
+ Enabled: true
66
+
67
+ Style/MissingRespondToMissing:
68
+ Enabled: false
69
+
70
+ Style/NegatedIfElseCondition:
71
+ Enabled: true
72
+
73
+ Style/StringLiterals:
74
+ Enabled: false
75
+
76
+ Style/SwapValues:
77
+ Enabled: true
@@ -0,0 +1 @@
1
+ ruby 2.7.2
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5.8
4
+ - 2.6.6
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
7
+ script:
8
+ - bundle exec rspec
9
+ - bundle exec rubocop
@@ -0,0 +1,5 @@
1
+ # CHANGELOG
2
+
3
+ ## 1.0
4
+
5
+ - Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at adamgsteel@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in retry_on_error.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ retry_on_error (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ coderay (1.1.3)
11
+ diff-lcs (1.4.4)
12
+ method_source (1.0.0)
13
+ parallel (1.19.2)
14
+ parser (2.7.2.0)
15
+ ast (~> 2.4.1)
16
+ pry (0.13.1)
17
+ coderay (~> 1.1)
18
+ method_source (~> 1.0)
19
+ pry-doc (1.1.0)
20
+ pry (~> 0.11)
21
+ yard (~> 0.9.11)
22
+ rainbow (3.0.0)
23
+ rake (12.3.3)
24
+ regexp_parser (1.8.2)
25
+ rexml (3.2.4)
26
+ rspec (3.10.0)
27
+ rspec-core (~> 3.10.0)
28
+ rspec-expectations (~> 3.10.0)
29
+ rspec-mocks (~> 3.10.0)
30
+ rspec-core (3.10.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-expectations (3.10.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-mocks (3.10.0)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.0)
39
+ rubocop (1.2.0)
40
+ parallel (~> 1.10)
41
+ parser (>= 2.7.1.5)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8)
44
+ rexml
45
+ rubocop-ast (>= 1.0.1)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 1.4.0, < 2.0)
48
+ rubocop-ast (1.1.1)
49
+ parser (>= 2.7.1.5)
50
+ ruby-progressbar (1.10.1)
51
+ unicode-display_width (1.7.0)
52
+ yard (0.9.25)
53
+
54
+ PLATFORMS
55
+ ruby
56
+
57
+ DEPENDENCIES
58
+ pry
59
+ pry-doc
60
+ rake (~> 12.0)
61
+ retry_on_error!
62
+ rspec (~> 3.0)
63
+ rubocop
64
+
65
+ BUNDLED WITH
66
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Adam Steel
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.
@@ -0,0 +1,11 @@
1
+ [![Build Status](https://travis-ci.org/truecoach/retry_on_error.svg?branch=main)](https://travis-ci.org/truecoach/retry_on_error)
2
+
3
+
4
+ # RetryOnError
5
+
6
+ In process of open sourcing, don't use just yet
7
+
8
+ ## Usage
9
+
10
+ ```ruby
11
+ ```
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "retry_on_error"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "retry_on_error/version"
4
+ require "retry_on_error/errors"
5
+ require "retry_on_error/retrier"
6
+
7
+ module RetryOnError
8
+ def self.call(*args, **opts, &block)
9
+ Retrier.call(*args, **opts, &block)
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RetryOnError
4
+ class InvalidConfigError < StandardError; end
5
+ end
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RetryOnError
4
+ class Retrier
5
+ def self.call(*error_configs, delay: 0.5, max_wait: 0, &block)
6
+ new(*error_configs, delay: delay, max_wait: max_wait, &block).call
7
+ end
8
+
9
+ def initialize(*error_configs, delay:, max_wait:, &block)
10
+ self.error_configs = error_configs
11
+ self.delay = delay
12
+ self.max_wait = max_wait
13
+ self.block = block
14
+
15
+ validate_configs!
16
+ end
17
+
18
+ def call(start_time: Time.now)
19
+ block.call
20
+ rescue StandardError => e
21
+ raise unless retryable?(e, start_time: start_time)
22
+
23
+ sleep delay
24
+
25
+ call(start_time: start_time)
26
+ end
27
+
28
+ private
29
+
30
+ attr_accessor :block,
31
+ :delay,
32
+ :error_configs,
33
+ :max_wait
34
+
35
+ def retryable?(error, start_time:)
36
+ return false if Time.now - start_time >= max_wait
37
+
38
+ error_configs.any? { |c| config_error_match?(c, error) }
39
+ end
40
+
41
+ def config_error_match?(error_config, error)
42
+ if error_config.is_a?(Array)
43
+ error.class <= error_config[0] &&
44
+ error.message.match(error_config[1])
45
+ else
46
+ error.class <= error_config
47
+ end
48
+ end
49
+
50
+ def validate_configs!
51
+ invalid_config! unless error_configs.respond_to?(:all?)
52
+
53
+ return if error_configs.all? { |config| valid_config?(config) }
54
+
55
+ invalid_config!
56
+ end
57
+
58
+ def valid_config?(config)
59
+ config.is_a?(Array) ? valid_array_config?(config) : valid_single_config?(config)
60
+ rescue StandardError
61
+ false
62
+ end
63
+
64
+ def valid_array_config?(config)
65
+ config[0] <= Exception && config[1].is_a?(Regexp)
66
+ end
67
+
68
+ def valid_single_config?(config)
69
+ config <= Exception
70
+ end
71
+
72
+ def invalid_config!
73
+ msg = <<~MSG
74
+
75
+ Invalid error config object.
76
+
77
+ Expected an array of either error classes OR
78
+ 2 item arrays: [error class, regex]
79
+
80
+ Example:
81
+
82
+ # [
83
+ # [ ActiveModel::ValidationError, /message/ ],
84
+ # CustomError
85
+ # ]
86
+
87
+ Instead got:
88
+
89
+ # #{error_configs.inspect}
90
+ MSG
91
+
92
+ raise InvalidConfigError, msg
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RetryOnError
4
+ VERSION = "0.1.1"
5
+ end
Binary file
@@ -0,0 +1,32 @@
1
+ require_relative 'lib/retry_on_error/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "retry_on_error"
5
+ spec.version = RetryOnError::VERSION
6
+ spec.authors = ["Adam Steel"]
7
+ spec.email = ["adamgsteel@gmail.com"]
8
+
9
+ spec.summary = %q{Easily customize retry behavior for an operation}
10
+ spec.description = %q{Especially useful for handling cross network calls.}
11
+ spec.homepage = "https://github.com/truecoach/retry_on_error"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = spec.homepage
17
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ spec.add_development_dependency 'rspec'
29
+ spec.add_development_dependency 'pry'
30
+ spec.add_development_dependency 'pry-doc'
31
+ spec.add_development_dependency 'rubocop'
32
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retry_on_error
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Steel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-11-05 00:00:00.000000000 Z
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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-doc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Especially useful for handling cross network calls.
70
+ email:
71
+ - adamgsteel@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - ".tool-versions"
80
+ - ".travis.yml"
81
+ - CHANGELOG.md
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - lib/retry_on_error.rb
91
+ - lib/retry_on_error/errors.rb
92
+ - lib/retry_on_error/retrier.rb
93
+ - lib/retry_on_error/version.rb
94
+ - retry_on_error-0.1.0.gem
95
+ - retry_on_error.gemspec
96
+ homepage: https://github.com/truecoach/retry_on_error
97
+ licenses:
98
+ - MIT
99
+ metadata:
100
+ homepage_uri: https://github.com/truecoach/retry_on_error
101
+ source_code_uri: https://github.com/truecoach/retry_on_error
102
+ changelog_uri: https://github.com/truecoach/retry_on_error/CHANGELOG.md
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 2.3.0
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.1.4
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Easily customize retry behavior for an operation
122
+ test_files: []