switch_gear 0.2.0 → 0.3.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/.gitignore +1 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +7 -4
- data/docs/SwitchGear.html +127 -0
- data/docs/SwitchGear/CircuitBreaker.html +1004 -0
- data/docs/SwitchGear/CircuitBreaker/Failure.html +448 -0
- data/docs/SwitchGear/CircuitBreaker/Memory.html +929 -0
- data/docs/SwitchGear/CircuitBreaker/OpenError.html +124 -0
- data/docs/SwitchGear/CircuitBreaker/Redis.html +1032 -0
- data/docs/_config.yml +1 -0
- data/docs/_index.html +182 -0
- data/docs/class_list.html +51 -0
- data/docs/css/common.css +1 -0
- data/docs/css/full_list.css +58 -0
- data/docs/css/style.css +492 -0
- data/docs/file.README.html +205 -0
- data/docs/file_list.html +56 -0
- data/docs/frames.html +17 -0
- data/docs/index.html +205 -0
- data/docs/js/app.js +243 -0
- data/docs/js/full_list.js +216 -0
- data/docs/js/jquery.js +4 -0
- data/docs/method_list.html +315 -0
- data/docs/top-level-namespace.html +110 -0
- data/lib/switch_gear.rb +1 -0
- data/lib/switch_gear/circuit_breaker.rb +9 -4
- data/lib/switch_gear/circuit_breaker/failure.rb +2 -2
- data/lib/switch_gear/circuit_breaker/memory.rb +4 -4
- data/lib/switch_gear/circuit_breaker/redis.rb +15 -5
- data/lib/switch_gear/version.rb +1 -1
- metadata +23 -2
@@ -6,7 +6,7 @@ module SwitchGear
|
|
6
6
|
failure = JSON.parse(json)
|
7
7
|
error = Object.const_get(failure["error"])
|
8
8
|
error = error.new(failure["message"])
|
9
|
-
new(error, Time.
|
9
|
+
new(error, Time.at(failure["timestamp"]).utc)
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(error, recorded = Time.now.utc)
|
@@ -26,7 +26,7 @@ module SwitchGear
|
|
26
26
|
JSON.generate({
|
27
27
|
error: error.class,
|
28
28
|
message: error.message,
|
29
|
-
timestamp: timestamp.
|
29
|
+
timestamp: timestamp.to_i
|
30
30
|
})
|
31
31
|
end
|
32
32
|
|
@@ -3,17 +3,17 @@ module SwitchGear
|
|
3
3
|
class Memory
|
4
4
|
include CircuitBreaker
|
5
5
|
|
6
|
-
# The main runner, must respond to #call
|
6
|
+
# The main runner, must respond to #call.
|
7
7
|
# @return [Proc/Lambda] the runner
|
8
8
|
attr_accessor :circuit
|
9
9
|
# The count of failures
|
10
|
-
# @return [Integer] the amount of failures to permit. Defaults to 10 seconds
|
10
|
+
# @return [Integer] the amount of failures to permit. Defaults to 10 seconds.
|
11
11
|
attr_accessor :failure_limit
|
12
|
-
# The amount of time in seconds before a breaker should reset if currently open. Defaults to 5
|
12
|
+
# The amount of time in seconds before a breaker should reset if currently open. Defaults to 5.
|
13
13
|
# @return [Integer]
|
14
14
|
attr_accessor :reset_timeout
|
15
15
|
# The current logger
|
16
|
-
# @return [Object] - The logger sent in at initialization. Defaults to ruby's std Logger class
|
16
|
+
# @return [Object] - The logger sent in at initialization. Defaults to ruby's std Logger class.
|
17
17
|
attr_accessor :logger
|
18
18
|
# The current state
|
19
19
|
# @return [Symbol] should always return either :open, :closed or :half-open.
|
@@ -68,23 +68,33 @@ module SwitchGear
|
|
68
68
|
client.set(state_namespace, state.to_s)
|
69
69
|
end
|
70
70
|
|
71
|
+
def failure_count
|
72
|
+
client.llen(fail_namespace)
|
73
|
+
end
|
74
|
+
|
75
|
+
def most_recent_failure
|
76
|
+
Failure.from_json(client.lindex(fail_namespace, -1))
|
77
|
+
end
|
78
|
+
|
71
79
|
def failures
|
72
|
-
|
73
|
-
|
80
|
+
if failure_count > 0
|
81
|
+
redis_fails = client.lrange(fail_namespace, 0, -1)
|
82
|
+
return redis_fails.map { |f| Failure.from_json(f) }
|
83
|
+
end
|
74
84
|
# if there are no failures in redis, set it to empty
|
75
85
|
self.failures = []
|
76
86
|
[]
|
77
87
|
end
|
78
88
|
|
79
89
|
def add_failure(failure)
|
80
|
-
client.
|
90
|
+
client.rpush(fail_namespace, failure.to_json)
|
81
91
|
end
|
82
92
|
|
83
93
|
# failures= requires we replace what is currently in redis
|
84
94
|
# with the new value so we delete all entries first then add
|
85
95
|
def failures=(failures)
|
86
96
|
client.del(fail_namespace)
|
87
|
-
failures.each { |f| client.
|
97
|
+
failures.each { |f| client.rpush(fail_namespace, f.to_json) }
|
88
98
|
end
|
89
99
|
|
90
100
|
private
|
@@ -100,7 +110,7 @@ module SwitchGear
|
|
100
110
|
def run_validations
|
101
111
|
# call super to ensure module has what it needs
|
102
112
|
super
|
103
|
-
redis_commands = [:
|
113
|
+
redis_commands = [:rpush, :lindex, :llen, :del, :set, :get]
|
104
114
|
if !redis_commands.all? { |c| client.respond_to?(c) }
|
105
115
|
raise NotImplementedError.new("Missing Methods. Your client must implement: #{redis_commands}")
|
106
116
|
end
|
data/lib/switch_gear/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: switch_gear
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Ross
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,6 +140,27 @@ files:
|
|
140
140
|
- Rakefile
|
141
141
|
- bin/console
|
142
142
|
- bin/setup
|
143
|
+
- docs/SwitchGear.html
|
144
|
+
- docs/SwitchGear/CircuitBreaker.html
|
145
|
+
- docs/SwitchGear/CircuitBreaker/Failure.html
|
146
|
+
- docs/SwitchGear/CircuitBreaker/Memory.html
|
147
|
+
- docs/SwitchGear/CircuitBreaker/OpenError.html
|
148
|
+
- docs/SwitchGear/CircuitBreaker/Redis.html
|
149
|
+
- docs/_config.yml
|
150
|
+
- docs/_index.html
|
151
|
+
- docs/class_list.html
|
152
|
+
- docs/css/common.css
|
153
|
+
- docs/css/full_list.css
|
154
|
+
- docs/css/style.css
|
155
|
+
- docs/file.README.html
|
156
|
+
- docs/file_list.html
|
157
|
+
- docs/frames.html
|
158
|
+
- docs/index.html
|
159
|
+
- docs/js/app.js
|
160
|
+
- docs/js/full_list.js
|
161
|
+
- docs/js/jquery.js
|
162
|
+
- docs/method_list.html
|
163
|
+
- docs/top-level-namespace.html
|
143
164
|
- examples/example.rb
|
144
165
|
- examples/example_redis.rb
|
145
166
|
- lib/switch_gear.rb
|