kudan 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/kudan/configuration.rb +15 -3
- data/lib/kudan/kudan.rb +42 -1
- data/lib/kudan/version.rb +1 -1
- metadata +3 -4
- data/lib/kudan/retryable.rb +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 237d005c6fbd00ce363662958211e1353117110f
|
4
|
+
data.tar.gz: 211a4ee62a5c042f894968b31e0636749be68afe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b94c5fa6739c7cec047e3b173df186aed43b58e6995a2acfb27f5fcb2b05f28637d9e1283ae3e4eb8697eb438ccd8b3571a9aee56189e9667496246aa48a0bcf
|
7
|
+
data.tar.gz: d9c1cd24e5e6e4d945f7610401524d0ca89e614f19b09f85c6df228d22b023db8d9e4464bf0d0e70af98ab7dd62cfb7a16b78934f658c52871b3ac15c34eec0f
|
data/README.md
CHANGED
data/lib/kudan/configuration.rb
CHANGED
@@ -1,7 +1,19 @@
|
|
1
1
|
require 'active_support/configurable'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
module Kudan
|
4
|
+
class Configuration
|
5
|
+
OPTIONS = [:enabled, :sleep_seconds, :tries].map(&:freeze).freeze
|
5
6
|
|
6
|
-
|
7
|
+
attr_accessor :enabled, :sleep_seconds, :tries
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@enabled = true
|
11
|
+
@tries = 2
|
12
|
+
@sleep_seconds = 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
OPTIONS.map { |e| [e, send(e)] }.to_h
|
17
|
+
end
|
18
|
+
end
|
7
19
|
end
|
data/lib/kudan/kudan.rb
CHANGED
@@ -1,2 +1,43 @@
|
|
1
|
-
require '
|
1
|
+
require 'configuration'
|
2
2
|
require 'version'
|
3
|
+
|
4
|
+
module Kudan
|
5
|
+
class << self
|
6
|
+
def disable
|
7
|
+
configuration.enabled = false
|
8
|
+
end
|
9
|
+
|
10
|
+
def enabled?
|
11
|
+
configuration.enabled
|
12
|
+
end
|
13
|
+
|
14
|
+
def enable
|
15
|
+
configuration.enabled = true
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def retryable(options = {})
|
23
|
+
opts = configuration.config.merge(options)
|
24
|
+
enabled = opts.fetch(:enabled)
|
25
|
+
sleep_seconds = opts.fetch(:sleep_seconds)
|
26
|
+
tries = opts.fetch(:tries)
|
27
|
+
|
28
|
+
retries = 0
|
29
|
+
retry_exception = nil
|
30
|
+
begin
|
31
|
+
yield retries, retry_exception
|
32
|
+
rescue StandardError => exception
|
33
|
+
raise unless enabled
|
34
|
+
raise if retries + 1 > tries
|
35
|
+
|
36
|
+
sleep(sleep_seconds)
|
37
|
+
retries += 1
|
38
|
+
retry_exception = exception
|
39
|
+
retry
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/kudan/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kudan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- taki3
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -70,7 +70,6 @@ files:
|
|
70
70
|
- kudan.gemspec
|
71
71
|
- lib/kudan/configuration.rb
|
72
72
|
- lib/kudan/kudan.rb
|
73
|
-
- lib/kudan/retryable.rb
|
74
73
|
- lib/kudan/version.rb
|
75
74
|
homepage: https://github.com/ayindi/kudan
|
76
75
|
licenses:
|
@@ -92,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
91
|
version: '0'
|
93
92
|
requirements: []
|
94
93
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.6.
|
94
|
+
rubygems_version: 2.6.11
|
96
95
|
signing_key:
|
97
96
|
specification_version: 4
|
98
97
|
summary: Allow retry code blocks
|
data/lib/kudan/retryable.rb
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
require 'configuration'
|
2
|
-
|
3
|
-
module Retryable
|
4
|
-
Configuration.configure do |config|
|
5
|
-
config.enabled = true
|
6
|
-
config.sleep_seconds = 1
|
7
|
-
config.tries = 2
|
8
|
-
end
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def disable
|
12
|
-
Configuration.enabled = false
|
13
|
-
end
|
14
|
-
|
15
|
-
def enabled?
|
16
|
-
Configuration.enabled
|
17
|
-
end
|
18
|
-
|
19
|
-
def enable
|
20
|
-
Configuration.enabled = true
|
21
|
-
end
|
22
|
-
|
23
|
-
def retryable(options = {})
|
24
|
-
opts = Configuration.config.merge(options)
|
25
|
-
enabled = opts.fetch(:enabled)
|
26
|
-
sleep_seconds = opts.fetch(:sleep_seconds)
|
27
|
-
tries = opts.fetch(:tries)
|
28
|
-
|
29
|
-
retries = 0
|
30
|
-
retry_exception = nil
|
31
|
-
begin
|
32
|
-
yield retries, retry_exception
|
33
|
-
rescue StandardError => exception
|
34
|
-
raise unless enabled
|
35
|
-
raise if retries + 1 > tries
|
36
|
-
|
37
|
-
sleep(sleep_seconds)
|
38
|
-
retries += 1
|
39
|
-
retry_exception = exception
|
40
|
-
retry
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|