stubbornly 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1205ff4f8568bb88aca04e7f902a002865684100594a40dd3b1b2ad34c3e2590
4
+ data.tar.gz: 48b4637aa7db561154399bb69c0f0b1b289700c606d3550a11f139daa4bedffb
5
+ SHA512:
6
+ metadata.gz: 8c0522171461dccbaf95ad5286d78296201bc3a9bfbf8a06b9a22499a1c74eea32a81c424cca81feba69dd96f269099b36971f9f3d61e1b24bf8e45595d9a06c
7
+ data.tar.gz: 0ceedfba3af82388158b7d848650b226384d8337d553361a0e9759703c781e8d56601410dd436d993a3cd675a2b55be6fa072bcc5b9a3bfa5592cb3063c0382f
data/.gitignore ADDED
@@ -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,6 @@
1
+ --color
2
+ --format documentation
3
+ --tty
4
+ --order random
5
+ --require 'spec_helper'
6
+ -I spec/lib
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ DisplayCopNames:
5
+ Enabled: true
6
+
7
+ DisplayStyleGuide:
8
+ Enabled: true
9
+
10
+ Metrics/BlockLength:
11
+ Exclude:
12
+ - spec/**/*
13
+
14
+ Metrics/LineLength:
15
+ Max: 160
16
+
17
+ Style/Documentation:
18
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,25 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2018-07-01 13:37:09 +0200 using RuboCop version 0.57.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Metrics/AbcSize:
11
+ Max: 22
12
+
13
+ # Offense count: 1
14
+ Metrics/CyclomaticComplexity:
15
+ Max: 7
16
+
17
+ # Offense count: 2
18
+ # Configuration parameters: CountComments.
19
+ Metrics/MethodLength:
20
+ Max: 24
21
+
22
+ # Offense count: 1
23
+ Security/Eval:
24
+ Exclude:
25
+ - 'spec/unit/examples_spec.rb'
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in stubbornly.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,122 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stubbornly (0.1.0)
5
+ null-logger
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ ast (2.4.0)
13
+ byebug (10.0.2)
14
+ coderay (1.1.2)
15
+ diff-lcs (1.3)
16
+ domain_name (0.5.20180417)
17
+ unf (>= 0.0.5, < 1.0.0)
18
+ ffi (1.9.25)
19
+ formatador (0.2.5)
20
+ guard (2.14.2)
21
+ formatador (>= 0.2.4)
22
+ listen (>= 2.7, < 4.0)
23
+ lumberjack (>= 1.0.12, < 2.0)
24
+ nenv (~> 0.1)
25
+ notiffany (~> 0.0)
26
+ pry (>= 0.9.12)
27
+ shellany (~> 0.0)
28
+ thor (>= 0.18.1)
29
+ guard-bundler (2.1.0)
30
+ bundler (~> 1.0)
31
+ guard (~> 2.2)
32
+ guard-compat (~> 1.1)
33
+ guard-compat (1.2.1)
34
+ guard-rspec (4.7.3)
35
+ guard (~> 2.1)
36
+ guard-compat (~> 1.1)
37
+ rspec (>= 2.99.0, < 4.0)
38
+ http (3.3.0)
39
+ addressable (~> 2.3)
40
+ http-cookie (~> 1.0)
41
+ http-form_data (~> 2.0)
42
+ http_parser.rb (~> 0.6.0)
43
+ http-cookie (1.0.3)
44
+ domain_name (~> 0.5)
45
+ http-form_data (2.1.1)
46
+ http_parser.rb (0.6.0)
47
+ jaro_winkler (1.5.1)
48
+ listen (3.1.5)
49
+ rb-fsevent (~> 0.9, >= 0.9.4)
50
+ rb-inotify (~> 0.9, >= 0.9.7)
51
+ ruby_dep (~> 1.2)
52
+ lumberjack (1.0.13)
53
+ method_source (0.9.0)
54
+ nenv (0.3.0)
55
+ notiffany (0.1.1)
56
+ nenv (~> 0.1)
57
+ shellany (~> 0.0)
58
+ null-logger (0.1.5)
59
+ parallel (1.12.1)
60
+ parser (2.5.1.0)
61
+ ast (~> 2.4.0)
62
+ powerpack (0.1.2)
63
+ pry (0.11.3)
64
+ coderay (~> 1.1.0)
65
+ method_source (~> 0.9.0)
66
+ pry-byebug (3.6.0)
67
+ byebug (~> 10.0)
68
+ pry (~> 0.10)
69
+ public_suffix (3.0.2)
70
+ rainbow (3.0.0)
71
+ rake (12.3.1)
72
+ rb-fsevent (0.10.3)
73
+ rb-inotify (0.9.10)
74
+ ffi (>= 0.5.0, < 2)
75
+ rspec (3.7.0)
76
+ rspec-core (~> 3.7.0)
77
+ rspec-expectations (~> 3.7.0)
78
+ rspec-mocks (~> 3.7.0)
79
+ rspec-core (3.7.1)
80
+ rspec-support (~> 3.7.0)
81
+ rspec-expectations (3.7.0)
82
+ diff-lcs (>= 1.2.0, < 2.0)
83
+ rspec-support (~> 3.7.0)
84
+ rspec-mocks (3.7.0)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.7.0)
87
+ rspec-support (3.7.1)
88
+ rubocop (0.57.2)
89
+ jaro_winkler (~> 1.5.1)
90
+ parallel (~> 1.10)
91
+ parser (>= 2.5)
92
+ powerpack (~> 0.1)
93
+ rainbow (>= 2.2.2, < 4.0)
94
+ ruby-progressbar (~> 1.7)
95
+ unicode-display_width (~> 1.0, >= 1.0.1)
96
+ ruby-progressbar (1.9.0)
97
+ ruby_dep (1.5.0)
98
+ shellany (0.0.1)
99
+ thor (0.20.0)
100
+ unf (0.1.4)
101
+ unf_ext
102
+ unf_ext (0.0.7.5)
103
+ unicode-display_width (1.4.0)
104
+
105
+ PLATFORMS
106
+ ruby
107
+
108
+ DEPENDENCIES
109
+ bundler
110
+ guard
111
+ guard-bundler
112
+ guard-rspec
113
+ http
114
+ pry
115
+ pry-byebug
116
+ rake
117
+ rspec
118
+ rubocop
119
+ stubbornly!
120
+
121
+ BUNDLED WITH
122
+ 1.16.2
data/Guardfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ guard :bundler do
4
+ require 'guard/bundler'
5
+ require 'guard/bundler/verify'
6
+ helper = Guard::Bundler::Verify.new
7
+ files = ['Gemfile']
8
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
9
+ files.each { |file| watch(helper.real_path(file)) }
10
+ end
11
+
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ require 'guard/rspec/dsl'
14
+ dsl = Guard::RSpec::Dsl.new(self)
15
+
16
+ rspec = dsl.rspec
17
+ watch(rspec.spec_helper) { rspec.spec_dir }
18
+ watch(rspec.spec_files)
19
+ watch(%r{^lib/.*/(.+)\.rb$}) { |m| "spec/unit/#{m[1]}_spec.rb" }
20
+ dsl.watch_spec_files_for(dsl.ruby.lib_files)
21
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
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.
data/README.markdown ADDED
@@ -0,0 +1,37 @@
1
+ # Stubbornly
2
+
3
+ [![Build Status](https://travis-ci.org/suhlig/stubbornly.svg?branch=master)](https://travis-ci.org/suhlig/stubbornly)
4
+
5
+ Stubbornly retries a given block until the maximum number of attempts or timeout has been reached.
6
+
7
+ ## Example
8
+
9
+ ```ruby
10
+ require 'stubbornly'
11
+ require 'http'
12
+ require 'logger'
13
+
14
+ class Checker
15
+ def initialize(url)
16
+ @url = url
17
+ @logger = Logger.new(STDOUT)
18
+ @stubbornly = Stubbornly.new(logger: @logger)
19
+ end
20
+
21
+ def up?
22
+ @stubbornly.retry(timeout: 3) do
23
+ HTTP.get(@url)
24
+ end
25
+ end
26
+ end
27
+
28
+ if Checker.new('http://localhost:8765').up?
29
+ puts "Website is up"
30
+ else
31
+ warn "We are DOWN!"
32
+ end
33
+ ```
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+ RuboCop::RakeTask.new
10
+
11
+ task default: %i[rubocop spec]
data/lib/stubbornly.rb ADDED
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'null_logger'
4
+ require 'English'
5
+
6
+ class Stubbornly
7
+ def initialize(logger: NullLogger.new)
8
+ @logger = logger
9
+ end
10
+
11
+ def retry(timeout: Float::INFINITY, attempts: Float::MAX)
12
+ @logger.debug("Starting first of not more than #{attempts} attempts") if attempts < Float::MAX
13
+ @logger.debug("Will time out after #{timeout}s") unless timeout.infinite?
14
+
15
+ attempt = 0
16
+ start = Time.now
17
+
18
+ begin
19
+ @logger.info "Attempt ##{attempt}"
20
+ yield.tap do
21
+ @logger.info "Success after #{elapsed_since(start)}s and #{attempt} attempts"
22
+ end
23
+ rescue StandardError
24
+ attempt += 1
25
+ retry_after = 2**attempt - 1
26
+ @logger.warn "#{$ERROR_INFO.message}. Trying again in #{retry_after}s."
27
+
28
+ if attempt >= attempts
29
+ @logger.error "Maximum number of attempts (#{attempt}) reached"
30
+ return false
31
+ end
32
+
33
+ if elapsed_since(start) >= timeout
34
+ @logger.info "Timed out after #{elapsed_since(start)}s"
35
+ return false
36
+ end
37
+
38
+ sleep(retry_after)
39
+ retry
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def elapsed_since(start)
46
+ Time.now - start
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Stubbornly
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'stubbornly/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'stubbornly'
9
+ spec.version = Stubbornly::VERSION
10
+ spec.authors = ['Steffen Uhlig']
11
+ spec.email = ['steffen@familie-uhlig.net']
12
+
13
+ spec.summary = 'Retries with timeout and max attempts'
14
+ spec.description = 'Stubbornly retries a given block until the maximum number of attempts or timeout has been reached.'
15
+ spec.homepage = 'https://github.com/suhlig/stubbornly'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_dependency 'null-logger'
26
+
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'guard'
29
+ spec.add_development_dependency 'guard-bundler'
30
+ spec.add_development_dependency 'guard-rspec'
31
+ spec.add_development_dependency 'http'
32
+ spec.add_development_dependency 'pry'
33
+ spec.add_development_dependency 'pry-byebug'
34
+ spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'rspec'
36
+ spec.add_development_dependency 'rubocop'
37
+ end
metadata ADDED
@@ -0,0 +1,213 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: stubbornly
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Steffen Uhlig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: null-logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
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: guard
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: guard-bundler
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
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: http
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Stubbornly retries a given block until the maximum number of attempts
168
+ or timeout has been reached.
169
+ email:
170
+ - steffen@familie-uhlig.net
171
+ executables: []
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".rubocop.yml"
178
+ - ".rubocop_todo.yml"
179
+ - ".travis.yml"
180
+ - Gemfile
181
+ - Gemfile.lock
182
+ - Guardfile
183
+ - LICENSE.txt
184
+ - README.markdown
185
+ - Rakefile
186
+ - lib/stubbornly.rb
187
+ - lib/stubbornly/version.rb
188
+ - stubbornly.gemspec
189
+ homepage: https://github.com/suhlig/stubbornly
190
+ licenses:
191
+ - MIT
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - ">="
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubyforge_project:
209
+ rubygems_version: 2.7.6
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: Retries with timeout and max attempts
213
+ test_files: []