easy_retry 1.0.5 → 1.0.6

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
  SHA256:
3
- metadata.gz: b1628eebabfc2dd25f53d106aa0c665b20c2cc804ee7ff66a7372e784b02594d
4
- data.tar.gz: 0a1c561a8b510b25c580f4a6df1e3d2af2b913459c30c8c44d30d7985203bb96
3
+ metadata.gz: f8a0431c79ed41fca0259b18f9e168981590f4cc6371ab9e87def6539ab973c0
4
+ data.tar.gz: '08e27ce1c40d16f298e0819bc169030801ab3ca2434f6c23c8af6883c22f4a15'
5
5
  SHA512:
6
- metadata.gz: 8ace3d6f0a2e94bcc8e29cf04c9bf1b93a8e5e6d17a45c6b21d50d191a3279d50815f7f805aa21665aa114724ea6d064a9ade21e2939582464798ba6d01bf5d9
7
- data.tar.gz: 839d5afade1c5e160fb2c7c181f7b952f30bd147246c3956b268ad0039e3343bab1ba8b4a90b197e3cc0565cc193cdce77780c94ec6b8c7147d4ed3eaeda3652
6
+ metadata.gz: 69451e39a83b916f610693a987de7bbdc5964f28aa2c1cff8bde674b4967c57766b15182d2ab37f54b0ab640d8280b5deb72209ccda0f69e8147dd0dcf7ef358
7
+ data.tar.gz: 5951fc0c51e11bc8d21a6d729af1c51da95c439e1429b271693e1c7e62b341277beb81ba2a41dfd3085fb8128356cf8a99452671d80a5ae1f301ac7135764483
data/CHANGELOG.md CHANGED
@@ -1,10 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
- ## [1.0.6] - TBD
3
+ ## [Released]
4
4
 
5
- - Allow configuration of logger
5
+ ## [1.0.6] - 2022-11-22
6
6
 
7
- ## [Released]
7
+ - Allow configuration of logger
8
8
 
9
9
  ## [1.0.5] - 2022-11-22
10
10
 
data/Gemfile CHANGED
@@ -14,3 +14,5 @@ gem 'rubocop', '~> 1.21'
14
14
  gem 'pry'
15
15
 
16
16
  gem 'simplecov', require: false
17
+
18
+ gem 'logger'
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_retry (1.0.5)
4
+ easy_retry (1.0.6)
5
+ logger (~> 1.5.1)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
@@ -11,6 +12,7 @@ GEM
11
12
  diff-lcs (1.5.0)
12
13
  docile (1.4.0)
13
14
  json (2.6.2)
15
+ logger (1.5.1)
14
16
  method_source (1.0.0)
15
17
  parallel (1.22.1)
16
18
  parser (3.1.2.1)
@@ -62,6 +64,7 @@ PLATFORMS
62
64
 
63
65
  DEPENDENCIES
64
66
  easy_retry!
67
+ logger
65
68
  pry
66
69
  rake (~> 13.0)
67
70
  rspec (~> 3.0)
data/README.md CHANGED
@@ -101,6 +101,27 @@ The code above will produce the following output.
101
101
  => "This is try number 2"
102
102
  ```
103
103
 
104
+ ## Configuration
105
+
106
+ You can configure EasyRetry by adding an initializer as follows:
107
+
108
+ ```rb
109
+ EasyRetry.configure do |config|
110
+ # configuration options
111
+ end
112
+ ```
113
+
114
+ ### Logger
115
+
116
+ By default, EasyRetry uses [logger](https://rubygems.org/gems/logger) for logging errors. You can add your custom logger in the configuration using the `config.logger` option.
117
+
118
+ ```rb
119
+ # For Example, using Rails.logger
120
+ config.logger = Rails.logger
121
+ ```
122
+
123
+ NB: The logger should follow Rails Logger conventions.
124
+
104
125
  ## Retry delay
105
126
 
106
127
  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.
data/easy_retry.gemspec CHANGED
@@ -30,8 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ['lib']
32
32
 
33
- # Uncomment to register a new dependency of your gem
34
- # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_dependency 'logger', '~> 1.5.1'
35
34
 
36
35
  # For more information and examples about making a new gem, check out our
37
36
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ module EasyRetry
6
+ # Configuration class
7
+ class Configuration
8
+ attr_accessor :logger
9
+
10
+ def initialize
11
+ @logger = Logger.new($stdout)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Extend the Numeric class with a #tries method
4
+ class Numeric
5
+ # rubocop:disable Metrics/MethodLength
6
+ def tries(rescue_from: [StandardError])
7
+ raise ArgumentError, 'No block given' unless block_given?
8
+
9
+ rescue_from = Array(rescue_from)
10
+ max_retry = self
11
+ current_try = 1
12
+ result = nil
13
+
14
+ loop do
15
+ result = yield(current_try)
16
+
17
+ break
18
+ rescue *rescue_from => e
19
+ EasyRetry.logger.info "Error: #{e.message} (#{current_try}/#{max_retry})"
20
+
21
+ raise if current_try >= max_retry
22
+
23
+ sleep current_try * current_try
24
+
25
+ current_try += 1
26
+ end
27
+
28
+ result
29
+ end
30
+ # rubocop:enable Metrics/MethodLength
31
+
32
+ alias try tries
33
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyRetry
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.6'
5
5
  end
data/lib/easy_retry.rb CHANGED
@@ -1,39 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'easy_retry/core'
3
4
  require_relative 'easy_retry/version'
5
+ require_relative 'easy_retry/configuration'
4
6
 
5
- # Extend the Numeric class with a #tries method
6
- class Numeric
7
- # rubocop:disable Metrics/MethodLength
8
- def tries(rescue_from: [StandardError])
9
- raise ArgumentError, 'No block given' unless block_given?
10
-
11
- rescue_from = Array(rescue_from)
12
- max_retry = self
13
- current_try = 1
14
- result = nil
15
-
16
- loop do
17
- result = yield(current_try)
18
-
19
- break
20
- rescue *rescue_from => e
21
- if defined?(Rails)
22
- Rails.logger.error "Error: #{e.message} (#{current_try}/#{max_retry})"
23
- else
24
- puts "Error: #{e.message} (#{current_try}/#{max_retry})"
25
- end
26
-
27
- raise if current_try >= max_retry
28
-
29
- sleep current_try * current_try
7
+ # EasyRetry core module
8
+ module EasyRetry
9
+ class << self
10
+ def configuration
11
+ @configuration ||= EasyRetry::Configuration.new
12
+ end
30
13
 
31
- current_try += 1
14
+ def configure
15
+ yield(configuration)
32
16
  end
33
17
 
34
- result
18
+ def logger
19
+ configuration.logger
20
+ end
35
21
  end
36
- # rubocop:enable Metrics/MethodLength
37
-
38
- alias try tries
39
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robin Goudeketting, Peter Duijnstee
@@ -9,7 +9,21 @@ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
11
  date: 2022-11-22 00:00:00.000000000 Z
12
- dependencies: []
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.5.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.1
13
27
  description: Easily retry a block of code a predetermined number of times
14
28
  email:
15
29
  - robin@goudeketting.nl
@@ -29,6 +43,8 @@ files:
29
43
  - Rakefile
30
44
  - easy_retry.gemspec
31
45
  - lib/easy_retry.rb
46
+ - lib/easy_retry/configuration.rb
47
+ - lib/easy_retry/core.rb
32
48
  - lib/easy_retry/version.rb
33
49
  - sig/easy_retry.rbs
34
50
  homepage: https://github.com/GoudekettingRM/easy_retry