stoplight 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/stoplight.rb +1 -1
- data/lib/stoplight/data_store.rb +1 -1
- data/lib/stoplight/data_store/base.rb +8 -8
- data/lib/stoplight/data_store/memory.rb +15 -12
- data/lib/stoplight/failure.rb +1 -1
- data/lib/stoplight/light.rb +1 -1
- data/lib/stoplight/light/runnable.rb +6 -6
- data/lib/stoplight/notifier.rb +1 -1
- data/lib/stoplight/notifier/base.rb +1 -1
- data/lib/stoplight/notifier/generic.rb +2 -2
- data/lib/stoplight/version.rb +1 -1
- data/spec/stoplight/light/runnable_spec.rb +1 -1
- metadata +21 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8f2a2c82dbcebacbd22a8e7c945ded26322e528
|
4
|
+
data.tar.gz: 499150fa4ddaa7280f609e9171ab3d01a5486c6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb0064324bbfdf24238b17eb0d7f486981a1c327799441d0571549df292be4b5e0abf61a8d4697bceae3c7bca2c12f66cf6a6fc090349cb5592fb141c171dab1
|
7
|
+
data.tar.gz: 7cf937362b94a968b2ce0cd425e3cb7bf289f6c6708f5daa9386b4e06fedf493d736f9662fd878493894c9f5e1a39d35f0067bfeb06b134f962b6303c6d0e436
|
data/README.md
CHANGED
@@ -352,7 +352,7 @@ Stoplight::Light.default_notifiers += [notifier]
|
|
352
352
|
|
353
353
|
#### Honeybadger
|
354
354
|
|
355
|
-
Make sure you have [the Honeybadger gem][] (`~> 2.
|
355
|
+
Make sure you have [the Honeybadger gem][] (`~> 2.5`) installed before
|
356
356
|
configuring Stoplight.
|
357
357
|
|
358
358
|
``` rb
|
data/lib/stoplight.rb
CHANGED
data/lib/stoplight/data_store.rb
CHANGED
@@ -6,51 +6,51 @@ module Stoplight
|
|
6
6
|
class Base
|
7
7
|
# @return [Array<String>]
|
8
8
|
def names
|
9
|
-
|
9
|
+
raise NotImplementedError
|
10
10
|
end
|
11
11
|
|
12
12
|
# @param _light [Light]
|
13
13
|
# @return [Array(Array<Failure>, String)]
|
14
14
|
def get_all(_light)
|
15
|
-
|
15
|
+
raise NotImplementedError
|
16
16
|
end
|
17
17
|
|
18
18
|
# @param _light [Light]
|
19
19
|
# @return [Array<Failure>]
|
20
20
|
def get_failures(_light)
|
21
|
-
|
21
|
+
raise NotImplementedError
|
22
22
|
end
|
23
23
|
|
24
24
|
# @param _light [Light]
|
25
25
|
# @param _failure [Failure]
|
26
26
|
# @return [Fixnum]
|
27
27
|
def record_failure(_light, _failure)
|
28
|
-
|
28
|
+
raise NotImplementedError
|
29
29
|
end
|
30
30
|
|
31
31
|
# @param _light [Light]
|
32
32
|
# @return [Array<Failure>]
|
33
33
|
def clear_failures(_light)
|
34
|
-
|
34
|
+
raise NotImplementedError
|
35
35
|
end
|
36
36
|
|
37
37
|
# @param _light [Light]
|
38
38
|
# @return [String]
|
39
39
|
def get_state(_light)
|
40
|
-
|
40
|
+
raise NotImplementedError
|
41
41
|
end
|
42
42
|
|
43
43
|
# @param _light [Light]
|
44
44
|
# @param _state [String]
|
45
45
|
# @return [String]
|
46
46
|
def set_state(_light, _state)
|
47
|
-
|
47
|
+
raise NotImplementedError
|
48
48
|
end
|
49
49
|
|
50
50
|
# @param _light [Light]
|
51
51
|
# @return [String]
|
52
52
|
def clear_state(_light)
|
53
|
-
|
53
|
+
raise NotImplementedError
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
+
require 'concurrent'
|
4
|
+
|
3
5
|
module Stoplight
|
4
6
|
module DataStore
|
5
7
|
# @see Base
|
6
8
|
class Memory < Base
|
7
9
|
def initialize
|
8
|
-
@
|
10
|
+
@failures = Concurrent::Map.new { [] }
|
11
|
+
@states = Concurrent::Map.new { State::UNLOCKED }
|
12
|
+
@lock = Monitor.new
|
9
13
|
end
|
10
14
|
|
11
15
|
def names
|
@@ -17,23 +21,24 @@ module Stoplight
|
|
17
21
|
end
|
18
22
|
|
19
23
|
def get_failures(light)
|
20
|
-
all_failures[light.name]
|
24
|
+
all_failures[light.name]
|
21
25
|
end
|
22
26
|
|
23
27
|
def record_failure(light, failure)
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
@lock.synchronize do
|
29
|
+
n = light.threshold - 1
|
30
|
+
failures = get_failures(light).first(n).unshift(failure)
|
31
|
+
all_failures[light.name] = failures
|
32
|
+
failures.size
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
def clear_failures(light)
|
30
|
-
failures = get_failures(light)
|
31
37
|
all_failures.delete(light.name)
|
32
|
-
failures
|
33
38
|
end
|
34
39
|
|
35
40
|
def get_state(light)
|
36
|
-
all_states[light.name]
|
41
|
+
all_states[light.name]
|
37
42
|
end
|
38
43
|
|
39
44
|
def set_state(light, state)
|
@@ -41,19 +46,17 @@ module Stoplight
|
|
41
46
|
end
|
42
47
|
|
43
48
|
def clear_state(light)
|
44
|
-
state = get_state(light)
|
45
49
|
all_states.delete(light.name)
|
46
|
-
state
|
47
50
|
end
|
48
51
|
|
49
52
|
private
|
50
53
|
|
51
54
|
def all_failures
|
52
|
-
@
|
55
|
+
@failures
|
53
56
|
end
|
54
57
|
|
55
58
|
def all_states
|
56
|
-
@
|
59
|
+
@states
|
57
60
|
end
|
58
61
|
end
|
59
62
|
end
|
data/lib/stoplight/failure.rb
CHANGED
data/lib/stoplight/light.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Stoplight
|
4
4
|
class Light
|
5
|
-
module Runnable
|
5
|
+
module Runnable # rubocop:disable Style/Documentation
|
6
6
|
# @return [String]
|
7
7
|
def color
|
8
8
|
failures, state = failures_and_state
|
@@ -43,7 +43,7 @@ module Stoplight
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def run_red
|
46
|
-
|
46
|
+
raise Error::RedLight, name unless fallback
|
47
47
|
fallback.call(nil)
|
48
48
|
end
|
49
49
|
|
@@ -57,16 +57,16 @@ module Stoplight
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def not_blacklisted_error?(error)
|
60
|
-
blacklisted_errors.
|
60
|
+
!blacklisted_errors.empty? &&
|
61
61
|
blacklisted_errors.none? { |klass| error.is_a?(klass) }
|
62
62
|
end
|
63
63
|
|
64
64
|
def handle_error(error, on_failure)
|
65
|
-
|
66
|
-
|
65
|
+
raise error if whitelisted_errors.any? { |klass| error.is_a?(klass) }
|
66
|
+
raise error if not_blacklisted_error?(error)
|
67
67
|
size = record_failure(error)
|
68
68
|
on_failure.call(size, error) if on_failure
|
69
|
-
|
69
|
+
raise error unless fallback
|
70
70
|
fallback.call(error)
|
71
71
|
end
|
72
72
|
|
data/lib/stoplight/notifier.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Stoplight
|
4
4
|
module Notifier
|
5
|
-
module Generic
|
5
|
+
module Generic # rubocop:disable Style/Documentation
|
6
6
|
# @return [Proc]
|
7
7
|
attr_reader :formatter
|
8
8
|
|
@@ -23,7 +23,7 @@ module Stoplight
|
|
23
23
|
private
|
24
24
|
|
25
25
|
def put(_message)
|
26
|
-
|
26
|
+
raise NotImplementedError
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/stoplight/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stoplight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Desautels
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-01
|
13
|
+
date: 2016-03-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: concurrent-ruby
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.0'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: benchmark-ips
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,14 +144,14 @@ dependencies:
|
|
130
144
|
requirements:
|
131
145
|
- - "~>"
|
132
146
|
- !ruby/object:Gem::Version
|
133
|
-
version: '2.
|
147
|
+
version: '2.5'
|
134
148
|
type: :development
|
135
149
|
prerelease: false
|
136
150
|
version_requirements: !ruby/object:Gem::Requirement
|
137
151
|
requirements:
|
138
152
|
- - "~>"
|
139
153
|
- !ruby/object:Gem::Version
|
140
|
-
version: '2.
|
154
|
+
version: '2.5'
|
141
155
|
- !ruby/object:Gem::Dependency
|
142
156
|
name: rake
|
143
157
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,14 +200,14 @@ dependencies:
|
|
186
200
|
requirements:
|
187
201
|
- - "~>"
|
188
202
|
- !ruby/object:Gem::Version
|
189
|
-
version: 0.
|
203
|
+
version: 0.37.0
|
190
204
|
type: :development
|
191
205
|
prerelease: false
|
192
206
|
version_requirements: !ruby/object:Gem::Requirement
|
193
207
|
requirements:
|
194
208
|
- - "~>"
|
195
209
|
- !ruby/object:Gem::Version
|
196
|
-
version: 0.
|
210
|
+
version: 0.37.0
|
197
211
|
- !ruby/object:Gem::Dependency
|
198
212
|
name: slack-notifier
|
199
213
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,20 +236,6 @@ dependencies:
|
|
222
236
|
- - "~>"
|
223
237
|
- !ruby/object:Gem::Version
|
224
238
|
version: '0.8'
|
225
|
-
- !ruby/object:Gem::Dependency
|
226
|
-
name: yard
|
227
|
-
requirement: !ruby/object:Gem::Requirement
|
228
|
-
requirements:
|
229
|
-
- - "~>"
|
230
|
-
- !ruby/object:Gem::Version
|
231
|
-
version: '0.8'
|
232
|
-
type: :development
|
233
|
-
prerelease: false
|
234
|
-
version_requirements: !ruby/object:Gem::Requirement
|
235
|
-
requirements:
|
236
|
-
- - "~>"
|
237
|
-
- !ruby/object:Gem::Version
|
238
|
-
version: '0.8'
|
239
239
|
description: An implementation of the circuit breaker pattern.
|
240
240
|
email:
|
241
241
|
- camdez@gmail.com
|
@@ -313,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
313
313
|
version: '0'
|
314
314
|
requirements: []
|
315
315
|
rubyforge_project:
|
316
|
-
rubygems_version: 2.
|
316
|
+
rubygems_version: 2.6.0
|
317
317
|
signing_key:
|
318
318
|
specification_version: 4
|
319
319
|
summary: Traffic control for code.
|
@@ -341,4 +341,3 @@ test_files:
|
|
341
341
|
- spec/stoplight/state_spec.rb
|
342
342
|
- spec/stoplight/version_spec.rb
|
343
343
|
- spec/stoplight_spec.rb
|
344
|
-
has_rdoc:
|