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 +5 -5
- data/.rubocop.yml +34 -18
- data/Gemfile +7 -10
- data/Rakefile +2 -0
- data/lib/tlopo/retry/version.rb +4 -2
- data/lib/tlopo/retry.rb +32 -63
- data/tlopo-retry.gemspec +8 -5
- metadata +27 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d1961dc0719a0297e1278860e12db653b0fe5aa716c2bd15d84980527936f336
|
4
|
+
data.tar.gz: 702278c529f45dc6603adc85595d26c6e78ba0063410b29fcf29cb19d06f4e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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:
|
18
|
-
|
19
|
-
|
18
|
+
Max: 15
|
19
|
+
Metrics/PerceivedComplexity:
|
20
|
+
Max: 15
|
20
21
|
Metrics/ModuleLength:
|
21
22
|
Enabled: false
|
22
|
-
|
23
|
-
Enabled:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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-
|
5
|
+
# Specify your gem's dependencies in tlopo-cmd.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
end
|
8
|
+
gem 'rake', '~> 13.0'
|
9
|
+
|
10
|
+
gem 'minitest', '~> 5.0'
|
10
11
|
|
11
|
-
|
12
|
-
group :perf do
|
13
|
-
gem 'memory_profiler', '~> 0.9.8'
|
14
|
-
end
|
15
|
-
end
|
12
|
+
gem 'rubocop', '~> 1.21'
|
data/Rakefile
CHANGED
data/lib/tlopo/retry/version.rb
CHANGED
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 ||=
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
34
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
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('
|
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
|
-
|
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', '~>
|
37
|
+
spec.add_development_dependency('bundler', '~> 2.4')
|
36
38
|
spec.add_development_dependency('minitest', '~> 5.0')
|
37
|
-
spec.add_development_dependency('rake', '~>
|
38
|
-
spec.add_development_dependency('rubocop', '~>
|
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.
|
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:
|
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: '
|
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: '
|
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: '
|
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: '
|
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:
|
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:
|
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:
|
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
|
-
|
107
|
-
|
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: []
|