tlopo-retry 0.1.1 → 0.2.0

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
- SHA1:
3
- metadata.gz: 77ef23b75122a02c372f335adf6277b8b17bb7ed
4
- data.tar.gz: a7c1846fc1d8981a2c9e224d033936337644e67a
2
+ SHA256:
3
+ metadata.gz: d1961dc0719a0297e1278860e12db653b0fe5aa716c2bd15d84980527936f336
4
+ data.tar.gz: 702278c529f45dc6603adc85595d26c6e78ba0063410b29fcf29cb19d06f4e98
5
5
  SHA512:
6
- metadata.gz: d3789283628c94ebb4697d5e38e85f68486886cde318072298c17e69a054d87209b453679f7ca368c4dd788472e6fb60d85c0f215a83557579188161446988af
7
- data.tar.gz: 85ed915f99ad0a494b9b1f7901c29f02b39f6143ae4008f0e62963601d30ae2abe0fb3819fb1f5590ce08fd3b4c830ecc4db5c5ce4cf8f89ff0a2d1c5ad8c78d
6
+ metadata.gz: 95dc121f19785b8b447f173181761c028506e755f7b823c38b8f40e9e0e1b37b33dd49ba5a778dc5b06f9ac3f47928191ef6a37d1c93fd75c2df5e5971c4d28c
7
+ data.tar.gz: e2c482b9f7fc3d6f636dcb2e1e79e5d193d833419597ff2b92b71ea6298535ba09fc507a58ea7803f136e2452df6ff4819c9aa84701d0298c7adf74c192dad11
data/.rubocop.yml CHANGED
@@ -1,30 +1,46 @@
1
-
2
1
  AllCops:
3
2
  DisplayCopNames: true
4
- TargetRubyVersion: 2.2 # Oldest version kubeclient supports
3
+ TargetRubyVersion: 2.6
4
+ NewCops: enable
5
+ SuggestExtensions: false
6
+
7
+ Gemspec/DevelopmentDependencies:
8
+ EnforcedStyle: gemspec
9
+
5
10
  MethodLength:
6
11
  Enabled: false
7
12
  ClassLength:
8
13
  Enabled: false
9
- Metrics/AbcSize:
10
- Enabled: false
11
- Metrics/LineLength:
12
- Max: 100
13
14
  Metrics/ParameterLists:
14
15
  Max: 5
15
16
  CountKeywordArgs: false
16
17
  Metrics/CyclomaticComplexity:
17
- Max: 8
18
- Exclude:
19
- - lib/tlopo/retry.rb
18
+ Max: 15
19
+ Metrics/PerceivedComplexity:
20
+ Max: 15
20
21
  Metrics/ModuleLength:
21
22
  Enabled: false
22
- Style/MethodCallWithArgsParentheses:
23
- Enabled: true
24
- IgnoredMethods: [require, raise, include, attr_reader, refute, assert]
25
- Exclude: [Gemfile, Rakefile, kubeclient.gemspec]
26
- Security/MarshalLoad:
27
- Exclude:
28
- - test/**/*
29
- - lib/tlopo/retry.rb
30
-
23
+ Metrics/AbcSize:
24
+ Enabled: false
25
+ Naming/AccessorMethodName:
26
+ Enabled: false
27
+ Style/Documentation:
28
+ Enabled: false
29
+ Style/SpecialGlobalVars:
30
+ Enabled: false
31
+ Style/ConditionalAssignment:
32
+ Enabled: false
33
+ Style/ClassVars:
34
+ Enabled: false
35
+ Style/OptionalBooleanParameter:
36
+ Enabled: false
37
+ Layout/FirstHashElementIndentation:
38
+ Enabled: false
39
+ Layout/LineLength:
40
+ Max: 120
41
+ Lint/OrAssignmentToConstant:
42
+ Enabled: false
43
+ Lint/AmbiguousRegexpLiteral:
44
+ Enabled: false
45
+ Gemspec/RequireMFA:
46
+ Enabled: false
data/Gemfile CHANGED
@@ -1,15 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- # Specify your gem's dependencies in tlopo-retry.gemspec
5
+ # Specify your gem's dependencies in tlopo-cmd.gemspec
4
6
  gemspec
5
7
 
6
- group :test do
7
- gem 'coveralls', '~> 0.8.17'
8
- gem 'simplecov', '~> 0.12.0'
9
- end
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'minitest', '~> 5.0'
10
11
 
11
- if RUBY_VERSION > '2.1.0'
12
- group :perf do
13
- gem 'memory_profiler', '~> 0.9.8'
14
- end
15
- end
12
+ gem 'rubocop', '~> 1.21'
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'rubocop/rake_task'
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tlopo
2
- module Retry
3
- VERSION = '0.1.1'.freeze
4
+ class Retry
5
+ VERSION = '0.2.0'
4
6
  end
5
7
  end
data/lib/tlopo/retry.rb CHANGED
@@ -1,81 +1,50 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'tlopo/retry/version'
2
4
  require 'logger'
3
5
  require 'timeout'
4
6
 
5
7
  # Simple module so we have a namespace
6
8
  module Tlopo
7
- LOGGER ||= proc do
8
- logger = Logger.new(ENV['TLOPO_LOG_LEVEL'] ? STDERR : '/dev/null')
9
- logger.level = ENV['TLOPO_LOG_LEVEL'] ? ENV['TLOPO_LOG_LEVEL'].upcase.to_s : Logger::ERROR
10
- logger
11
- end.call
12
-
13
- # A reusable retry mechanism which supports timeout, cleanup and fork
14
- module Retry
15
- LOGGER = Tlopo::LOGGER
16
- LOGGER.debug("#{self} loaded")
17
- VALID_OPTS = %i[tries timeout interval fork cleanup].freeze
18
-
19
- def self.validate_opts(opts)
20
- opts.each_key do |k|
21
- msg = "Option #{k} is invalid. Valid options: #{VALID_OPTS}"
22
- raise msg unless VALID_OPTS.include?(k)
9
+ LOGGER ||= Logger.new $stderr
10
+
11
+ module Setters
12
+ def make_setter(*names)
13
+ names.each do |name|
14
+ define_method(name) do |val|
15
+ instance_variable_set("@#{name}", val)
16
+ self
17
+ end
23
18
  end
24
19
  end
20
+ end
25
21
 
26
- def self.retry(opts = {}, &block)
27
- validate_opts(opts)
28
- is_fork = opts[:fork]
29
- return local(opts, &block) unless is_fork
30
- return child(opts, &block) if is_fork
22
+ class Retry
23
+ extend Setters
24
+ make_setter :tries, :interval, :exponential_backoff, :error_types
25
+ def initialize(**args)
26
+ @tries = args[:tries] || 3
27
+ @interval = args[:interval] || 1
28
+ @exponential_backoff = args[:exponential_backoff] || false
29
+ @error_types = args[:error_types] || [StandardError]
31
30
  end
32
31
 
33
- def self.child(opts = {}, &block)
34
- read, write = IO.pipe
32
+ def run(&block)
33
+ count = 1
34
+ while count <= @tries
35
+ next unless block_given?
35
36
 
36
- pid = fork do
37
- read.close
38
37
  begin
39
- result = local(opts, &block)
40
- Marshal.dump({ result: result, error: nil }, write)
41
- rescue StandardError => e
42
- Marshal.dump({ result: nil, error: e }, write)
38
+ return instance_eval(&block)
39
+ rescue *@error_types => e
40
+ count += 1
41
+ time = @exponential_backoff ? @interval**count : @interval
42
+ sleep time
43
+ e
43
44
  end
44
45
  end
45
-
46
- write.close
47
- result = Marshal.load(read.read)
48
- Process.wait(pid)
49
- raise result[:error] if result[:error]
50
- result[:result]
51
- end
52
-
53
- def self.local(opts = {})
54
- tries = get_opt_value(opts, :tries, 3)
55
- timeout = get_opt_value(opts, :timeout, 0)
56
- interval = get_opt_value(opts, :interval, 1)
57
- desc = opts[:desc]
58
- cleanup = opts[:cleanup]
59
- LOGGER.debug("opts: #{opts}")
60
- LOGGER.debug("tries: #{tries}")
61
- count = 0
62
- begin
63
- count += 1
64
- Timeout.timeout(timeout) { yield }
65
- rescue StandardError => e
66
- raise e if count > tries
67
- msg = "#{self} Retrying to #{desc} #{count} out of #{tries}"
68
- LOGGER.info(msg) if desc
69
- LOGGER.debug("#{self} Calling cleanup") if cleanup
70
- cleanup.call if cleanup
71
- sleep(interval)
72
- retry
73
- end
74
- end
75
-
76
- def self.get_opt_value(opts, key, default)
77
- return opts[key] unless opts[key].nil?
78
- default
46
+ LOGGER.error e
47
+ raise "Retries exhausted, error: #{e.message}"
79
48
  end
80
49
  end
81
50
  end
data/tlopo-retry.gemspec CHANGED
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'tlopo/retry/version'
5
6
 
@@ -15,6 +16,7 @@ Gem::Specification.new do |spec|
15
16
  spec.description = spec.summary
16
17
  spec.homepage = 'https://github.com/tlopo-ruby/tlopo-retry'
17
18
  spec.license = 'MIT'
19
+ spec.required_ruby_version = '>= 2.6.0'
18
20
 
19
21
  # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
22
  # to allow pushing to a single host or delete this section to allow pushing to any host.
@@ -22,7 +24,7 @@ Gem::Specification.new do |spec|
22
24
  # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
23
25
  else
24
26
  raise 'RubyGems 2.0 or newer is required to protect against ' \
25
- 'public gem pushes.'
27
+ 'public gem pushes.'
26
28
  end
27
29
 
28
30
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
@@ -32,8 +34,9 @@ Gem::Specification.new do |spec|
32
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
35
  spec.require_paths = ['lib']
34
36
 
35
- spec.add_development_dependency('bundler', '~> 1.13')
37
+ spec.add_development_dependency('bundler', '~> 2.4')
36
38
  spec.add_development_dependency('minitest', '~> 5.0')
37
- spec.add_development_dependency('rake', '~> 10.0')
38
- spec.add_development_dependency('rubocop', '~> 0.52.1')
39
+ spec.add_development_dependency('rake', '~> 13.1')
40
+ spec.add_development_dependency('rubocop', '~> 1.6')
41
+ spec.add_development_dependency('simplecov', '~> 0.2')
39
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tlopo-retry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tlopo
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-10 00:00:00.000000000 Z
11
+ date: 2024-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '2.4'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '2.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,28 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.52.1
61
+ version: '1.6'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.52.1
68
+ version: '1.6'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
69
83
  description: A reusable retry mechanism which supports timeout, cleanup, and fork
70
84
  email:
71
85
  - tiagolopo@yahoo.com.br
@@ -88,7 +102,7 @@ homepage: https://github.com/tlopo-ruby/tlopo-retry
88
102
  licenses:
89
103
  - MIT
90
104
  metadata: {}
91
- post_install_message:
105
+ post_install_message:
92
106
  rdoc_options: []
93
107
  require_paths:
94
108
  - lib
@@ -96,16 +110,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
110
  requirements:
97
111
  - - ">="
98
112
  - !ruby/object:Gem::Version
99
- version: '0'
113
+ version: 2.6.0
100
114
  required_rubygems_version: !ruby/object:Gem::Requirement
101
115
  requirements:
102
116
  - - ">="
103
117
  - !ruby/object:Gem::Version
104
118
  version: '0'
105
119
  requirements: []
106
- rubyforge_project:
107
- rubygems_version: 2.5.1
108
- signing_key:
120
+ rubygems_version: 3.4.10
121
+ signing_key:
109
122
  specification_version: 4
110
123
  summary: A reusable retry mechanism which supports timeout, cleanup, and fork
111
124
  test_files: []