tlopo-retry 0.1.0 → 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: 0f301e35e2ab51e5baf34a2d6e94ead7f697996d
4
- data.tar.gz: 8643e0a47e62da8fc53f07fb8929116e916a398d
2
+ SHA256:
3
+ metadata.gz: d1961dc0719a0297e1278860e12db653b0fe5aa716c2bd15d84980527936f336
4
+ data.tar.gz: 702278c529f45dc6603adc85595d26c6e78ba0063410b29fcf29cb19d06f4e98
5
5
  SHA512:
6
- metadata.gz: fd9cd0de673f05b9690eb74b2b1a4ff68c9aae24221a5149be81fe5d324e47e5cee5e2fa7ec38ebdecb516facac82361fa49a431e75d124405612f43286cf31b
7
- data.tar.gz: 913da92c875082ba0e74746e26347c06e7e8b9ad2205e8879888a330961a41c8dc4d42f985f9f8bf26f444cfbb9c353f310b50d55f77cf99ef170a3380bf0391
6
+ metadata.gz: 95dc121f19785b8b447f173181761c028506e755f7b823c38b8f40e9e0e1b37b33dd49ba5a778dc5b06f9ac3f47928191ef6a37d1c93fd75c2df5e5971c4d28c
7
+ data.tar.gz: e2c482b9f7fc3d6f636dcb2e1e79e5d193d833419597ff2b92b71ea6298535ba09fc507a58ea7803f136e2452df6ff4819c9aa84701d0298c7adf74c192dad11
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .idea/
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.6
4
+ NewCops: enable
5
+ SuggestExtensions: false
6
+
7
+ Gemspec/DevelopmentDependencies:
8
+ EnforcedStyle: gemspec
9
+
10
+ MethodLength:
11
+ Enabled: false
12
+ ClassLength:
13
+ Enabled: false
14
+ Metrics/ParameterLists:
15
+ Max: 5
16
+ CountKeywordArgs: false
17
+ Metrics/CyclomaticComplexity:
18
+ Max: 15
19
+ Metrics/PerceivedComplexity:
20
+ Max: 15
21
+ Metrics/ModuleLength:
22
+ Enabled: false
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/.travis.yml CHANGED
@@ -1,5 +1,12 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.3.0
5
- before_install: gem install bundler -v 1.13.2
3
+ - "2.2"
4
+ - "2.3.0"
5
+ - "2.4.0"
6
+ sudo: false
7
+ cache: bundler
8
+ script: bundle exec rake $TASK
9
+ env:
10
+ - TASK=test
11
+ - TASK=rubocop
12
+ - TASK=test_with_coveralls
data/Gemfile CHANGED
@@ -1,4 +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
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'minitest', '~> 5.0'
11
+
12
+ gem 'rubocop', '~> 1.21'
data/README.md CHANGED
@@ -1,2 +1,80 @@
1
1
  # tlopo-retry
2
+ [![Gem Version](https://badge.fury.io/rb/tlopo-retry.svg)](http://badge.fury.io/rb/tlopo-retry)
3
+ [![Build Status](https://travis-ci.org/tlopo-ruby/tlopo-retry.svg?branch=master)](https://travis-ci.org/tlopo-ruby/tlopo-retry)
4
+ [![Code Climate](https://codeclimate.com/github/tlopo-ruby/tlopo-retry/badges/gpa.svg)](https://codeclimate.com/github/tlopo-ruby/tlopo-retry)
5
+ [![Dependency Status](https://gemnasium.com/tlopo-ruby/tlopo-retry.svg)](https://gemnasium.com/tlopo-ruby/tlopo-retry)
6
+ [![Coverage Status](https://coveralls.io/repos/github/tlopo-ruby/tlopo-retry/badge.svg?branch=master)](https://coveralls.io/github/tlopo-ruby/tlopo-retry?branch=master)
7
+
2
8
  A reusable retry mechanism which supports timeout, cleanup and fork
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'tlopo-retry'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ ```Bash
21
+ bundle
22
+ ```
23
+
24
+ Or install it yourself as:
25
+
26
+ ```Bash
27
+ gem install tlopo-retry
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Simple retry usage
33
+
34
+ ```ruby
35
+ # That will retry 3 times with no timeout and 1 second interval
36
+ Tlopo::Retry.retry do
37
+ TCPSocket.new('www.google.co.uk','8080').close
38
+ end
39
+ ```
40
+ Full options
41
+ ```ruby
42
+ require 'logger'
43
+ require 'socket'
44
+
45
+ # Enable logging
46
+ ENV['TLOPO_LOG_LEVEL'] = 'debug'
47
+
48
+ require 'tlopo/retry'
49
+
50
+ Tlopo::Retry.retry({
51
+ desc: 'check if port 8080 is open on www.google.co.uk',
52
+ tries: 2,
53
+ interval: 5,
54
+ timeout: 1,
55
+ cleanup: proc { p 'Run your cleanup code here'}
56
+ }) do
57
+ TCPSocket.new('www.google.co.uk','8080').close
58
+ end
59
+ ```
60
+
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/[my-github-username]/kubeclient/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Test your changes with `rake test rubocop`, add new tests if needed.
67
+ 4. If you added a new functionality, add it to README
68
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 6. Push to the branch (`git push origin my-new-feature`)
70
+ 7. Create a new Pull Request
71
+
72
+ ## Tests
73
+
74
+ This library is tested with Minitest.
75
+ Please run all tests before submitting a Pull Request, and add new tests for new functionality.
76
+
77
+ Running tests:
78
+ ```ruby
79
+ rake test
80
+ ```
data/Rakefile CHANGED
@@ -1,10 +1,18 @@
1
- require "bundler/gem_tasks"
2
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
+ require 'coveralls/rake/task'
7
+
8
+ task default: %i[test rubocop]
9
+ task test_with_coveralls: [:default, 'coveralls:push']
3
10
 
4
11
  Rake::TestTask.new(:test) do |t|
5
- t.libs << "test"
6
- t.libs << "lib"
12
+ t.libs << 'test'
13
+ t.libs << 'lib'
7
14
  t.test_files = FileList['test/**/*_test.rb']
8
15
  end
9
16
 
10
- task :default => :test
17
+ RuboCop::RakeTask.new
18
+ Coveralls::RakeTask.new
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Tlopo
2
- module Retry
3
- VERSION = "0.1.0"
4
+ class Retry
5
+ VERSION = '0.2.0'
4
6
  end
5
7
  end
data/lib/tlopo/retry.rb CHANGED
@@ -1,70 +1,50 @@
1
- require "tlopo/retry/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'tlopo/retry/version'
2
4
  require 'logger'
3
5
  require 'timeout'
4
6
 
7
+ # Simple module so we have a namespace
5
8
  module Tlopo
6
- LOGGER ||= proc do
7
- logger = Logger.new(ENV['TLOPO_LOG_LEVEL'] ? STDERR : '/dev/null')
8
- logger.level = ENV['TLOPO_LOG_LEVEL'] ? "#{ENV['TLOPO_LOG_LEVEL'].upcase}" : Logger::ERROR
9
- logger
10
- end.call
11
-
12
- end
13
-
14
- module Tlopo::Retry
15
- LOGGER = Tlopo::LOGGER
16
- LOGGER.debug "#{self} loaded"
17
- def self.retry(opts={},&block)
18
- is_fork = opts[:fork]
19
- return local(opts,&block) unless is_fork
20
- return child(opts,&block) if is_fork
21
- end
9
+ LOGGER ||= Logger.new $stderr
22
10
 
23
- private
24
- def self.child(opts={},&block)
25
- read, write = IO.pipe
26
-
27
- pid = fork do
28
- read.close
29
- begin
30
- result = local(opts,&block)
31
- Marshal.dump({result: result, error: nil}, write)
32
- rescue => e
33
- Marshal.dump({result:nil, error: e},write)
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
34
18
  end
35
19
  end
36
-
37
- write.close
38
- result = Marshal.load(read.read)
39
- Process.wait(pid)
40
- raise result[:error] if result[:error]
41
- result[:result]
42
20
  end
43
21
 
44
- def self.local(opts={},&block)
45
- tries = opts[:tries] || 3
46
- timeout = opts[:timeout] || 0
47
- interval = opts[:interval] || 1
48
- desc = opts[:desc]
49
- cleanup = opts[:cleanup]
50
- LOGGER.debug "opts: #{opts}"
51
- LOGGER.debug "tries: #{tries}"
52
- count = 0
53
- begin
54
- count += 1
55
- Timeout::timeout(timeout) { yield }
56
- rescue => e
57
- unless count > tries
58
- msg = "#{self} Retrying to #{desc} #{count} out of #{tries}"
59
- LOGGER.info msg if desc
60
- LOGGER.debug "#{self} Calling cleanup" if cleanup
61
- cleanup.call if cleanup
62
- sleep interval
63
- retry
64
- else
65
- raise e
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]
30
+ end
31
+
32
+ def run(&block)
33
+ count = 1
34
+ while count <= @tries
35
+ next unless block_given?
36
+
37
+ begin
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
44
+ end
66
45
  end
46
+ LOGGER.error e
47
+ raise "Retries exhausted, error: #{e.message}"
67
48
  end
68
49
  end
69
50
  end
70
-
data/tlopo-retry.gemspec CHANGED
@@ -1,38 +1,42 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
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
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "tlopo-retry"
8
+ spec.name = 'tlopo-retry'
8
9
  spec.version = Tlopo::Retry::VERSION
9
- spec.authors = ["tlopo"]
10
- spec.email = ["tiago@aw20.co.uk"]
10
+ spec.authors = ['tlopo']
11
+ spec.email = ['tiagolopo@yahoo.com.br']
11
12
 
12
- spec.summary = %q{
13
+ spec.summary = '
13
14
  A reusable retry mechanism which supports timeout, cleanup, and fork
14
- }
15
+ '
15
16
  spec.description = spec.summary
16
- spec.homepage = "https://github.com/tlopo-ruby/tlopo-retry"
17
- spec.license = "MIT"
17
+ spec.homepage = 'https://github.com/tlopo-ruby/tlopo-retry'
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.
21
23
  if spec.respond_to?(:metadata)
22
- #spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
24
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
23
25
  else
24
- raise "RubyGems 2.0 or newer is required to protect against " \
25
- "public gem pushes."
26
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
27
+ 'public gem pushes.'
26
28
  end
27
29
 
28
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
30
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
29
31
  f.match(%r{^(test|spec|features)/})
30
32
  end
31
- spec.bindir = "bin"
33
+ spec.bindir = 'bin'
32
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
- spec.require_paths = ["lib"]
35
+ spec.require_paths = ['lib']
34
36
 
35
- spec.add_development_dependency "bundler", "~> 1.13"
36
- spec.add_development_dependency "rake", "~> 10.0"
37
- spec.add_development_dependency "minitest", "~> 5.0"
37
+ spec.add_development_dependency('bundler', '~> 2.4')
38
+ spec.add_development_dependency('minitest', '~> 5.0')
39
+ spec.add_development_dependency('rake', '~> 13.1')
40
+ spec.add_development_dependency('rubocop', '~> 1.6')
41
+ spec.add_development_dependency('simplecov', '~> 0.2')
38
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.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: 2018-01-03 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,58 +16,85 @@ 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
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '10.0'
47
+ version: '13.1'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '10.0'
54
+ version: '13.1'
41
55
  - !ruby/object:Gem::Dependency
42
- name: minitest
56
+ name: rubocop
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '5.0'
61
+ version: '1.6'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '5.0'
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'
55
83
  description: A reusable retry mechanism which supports timeout, cleanup, and fork
56
84
  email:
57
- - tiago@aw20.co.uk
85
+ - tiagolopo@yahoo.com.br
58
86
  executables: []
59
87
  extensions: []
60
88
  extra_rdoc_files: []
61
89
  files:
62
90
  - ".gitignore"
91
+ - ".rubocop.yml"
63
92
  - ".travis.yml"
64
93
  - Gemfile
65
94
  - LICENSE
66
95
  - LICENSE.txt
67
96
  - README.md
68
97
  - Rakefile
69
- - bin/console
70
- - bin/setup
71
98
  - lib/tlopo/retry.rb
72
99
  - lib/tlopo/retry/version.rb
73
100
  - tlopo-retry.gemspec
@@ -75,7 +102,7 @@ homepage: https://github.com/tlopo-ruby/tlopo-retry
75
102
  licenses:
76
103
  - MIT
77
104
  metadata: {}
78
- post_install_message:
105
+ post_install_message:
79
106
  rdoc_options: []
80
107
  require_paths:
81
108
  - lib
@@ -83,16 +110,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
83
110
  requirements:
84
111
  - - ">="
85
112
  - !ruby/object:Gem::Version
86
- version: '0'
113
+ version: 2.6.0
87
114
  required_rubygems_version: !ruby/object:Gem::Requirement
88
115
  requirements:
89
116
  - - ">="
90
117
  - !ruby/object:Gem::Version
91
118
  version: '0'
92
119
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.5.1
95
- signing_key:
120
+ rubygems_version: 3.4.10
121
+ signing_key:
96
122
  specification_version: 4
97
123
  summary: A reusable retry mechanism which supports timeout, cleanup, and fork
98
124
  test_files: []
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tlopo/retry"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
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