stoplight 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +8 -2
- data/lib/stoplight.rb +1 -0
- data/lib/stoplight/notifier/generic.rb +30 -0
- data/lib/stoplight/notifier/io.rb +7 -14
- data/lib/stoplight/notifier/slack.rb +6 -12
- data/lib/stoplight/version.rb +1 -1
- data/spec/stoplight/light/runnable_spec.rb +1 -0
- data/spec/stoplight/light_spec.rb +1 -0
- data/spec/stoplight/notifier/base_spec.rb +1 -1
- data/spec/stoplight/notifier/generic_spec.rb +50 -0
- data/spec/stoplight/notifier/hip_chat_spec.rb +1 -1
- data/spec/stoplight/notifier/io_spec.rb +4 -26
- data/spec/stoplight/notifier/slack_spec.rb +12 -27
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2da543aa5426e5354ed20f5e6d8547190597073d
|
4
|
+
data.tar.gz: 70aa5cfae4dbeec33fbefcadff88098317ccf0cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c022ff3500336be177976073695d9d197800e2ecdcfc9e1a498215f239b69e302b82c475f2ab8f7cfd6be508d20b9d9fd0c1170adfa70de1006de11751013c8
|
7
|
+
data.tar.gz: 857d9ea2421f83e516f64e6319421100d0bda5992875f023909c474ef78d140a173570a28944abc5865fbf5c2b603a79ce9689acd21013f5fa3e0b6e1c6174a8
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -14,7 +14,7 @@ breaker pattern in Ruby.
|
|
14
14
|
|
15
15
|
Does your code use unreliable systems, like a flaky database or a
|
16
16
|
spotty web service? Wrap those up with stoplights to prevent them
|
17
|
-
from affecting the rest of your application
|
17
|
+
from affecting the rest of your application.
|
18
18
|
|
19
19
|
Check out [stoplight-admin][] for controlling your stoplights.
|
20
20
|
|
@@ -135,6 +135,9 @@ light.color
|
|
135
135
|
# => "green"
|
136
136
|
```
|
137
137
|
|
138
|
+
The following errors are always allowed: `NoMemoryError`, `ScriptError`,
|
139
|
+
`SecurityError`, `SignalException`, `SystemExit`, and `SystemStackError`.
|
140
|
+
|
138
141
|
### Custom fallback
|
139
142
|
|
140
143
|
By default, stoplights will re-raise errors when they're green.
|
@@ -178,6 +181,8 @@ light.run
|
|
178
181
|
# Stoplight::Error::RedLight: example-5
|
179
182
|
```
|
180
183
|
|
184
|
+
The default threshold is `3`.
|
185
|
+
|
181
186
|
### Custom timeout
|
182
187
|
|
183
188
|
Stoplights will automatically attempt to recover after a certain
|
@@ -203,7 +208,8 @@ light.run
|
|
203
208
|
# RuntimeError:
|
204
209
|
```
|
205
210
|
|
206
|
-
Set the timeout to `-1` to disable
|
211
|
+
The default timeout is `60` seconds. Set the timeout to `-1` to disable
|
212
|
+
automatic recovery.
|
207
213
|
|
208
214
|
### Rails
|
209
215
|
|
data/lib/stoplight.rb
CHANGED
@@ -17,6 +17,7 @@ require 'stoplight/data_store/redis'
|
|
17
17
|
|
18
18
|
require 'stoplight/notifier'
|
19
19
|
require 'stoplight/notifier/base'
|
20
|
+
require 'stoplight/notifier/generic'
|
20
21
|
require 'stoplight/notifier/hip_chat'
|
21
22
|
require 'stoplight/notifier/io'
|
22
23
|
require 'stoplight/notifier/slack'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Stoplight
|
4
|
+
module Notifier
|
5
|
+
module Generic
|
6
|
+
# @return [Proc]
|
7
|
+
attr_reader :formatter
|
8
|
+
|
9
|
+
# @param object [Object]
|
10
|
+
# @param formatter [Proc, nil]
|
11
|
+
def initialize(object, formatter = nil)
|
12
|
+
@object = object
|
13
|
+
@formatter = formatter || Default::FORMATTER
|
14
|
+
end
|
15
|
+
|
16
|
+
# @see Base#notify
|
17
|
+
def notify(light, from_color, to_color, error)
|
18
|
+
message = formatter.call(light, from_color, to_color, error)
|
19
|
+
put(message)
|
20
|
+
message
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def put(_message)
|
26
|
+
fail NotImplementedError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,27 +1,20 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
require 'stringio'
|
4
|
-
|
5
3
|
module Stoplight
|
6
4
|
module Notifier
|
7
5
|
# @see Base
|
8
6
|
class IO < Base
|
9
|
-
|
10
|
-
attr_reader :formatter
|
11
|
-
# @return [::IO]
|
12
|
-
attr_reader :io
|
7
|
+
include Generic
|
13
8
|
|
14
|
-
# @
|
15
|
-
|
16
|
-
|
17
|
-
@io = io
|
18
|
-
@formatter = formatter || Default::FORMATTER
|
9
|
+
# @return [::IO]
|
10
|
+
def io
|
11
|
+
@object
|
19
12
|
end
|
20
13
|
|
21
|
-
|
22
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def put(message)
|
23
17
|
io.puts(message)
|
24
|
-
message
|
25
18
|
end
|
26
19
|
end
|
27
20
|
end
|
@@ -4,23 +4,17 @@ module Stoplight
|
|
4
4
|
module Notifier
|
5
5
|
# @see Base
|
6
6
|
class Slack < Base
|
7
|
-
|
8
|
-
attr_reader :formatter
|
7
|
+
include Generic
|
9
8
|
|
10
9
|
# @return [::Slack::Notifier]
|
11
|
-
|
12
|
-
|
13
|
-
# @param slack [::Slack::Notifier]
|
14
|
-
# @param formatter [Proc, nil]
|
15
|
-
def initialize(slack, formatter = nil)
|
16
|
-
@slack = slack
|
17
|
-
@formatter = formatter || Default::FORMATTER
|
10
|
+
def slack
|
11
|
+
@object
|
18
12
|
end
|
19
13
|
|
20
|
-
|
21
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def put(message)
|
22
17
|
slack.ping(message)
|
23
|
-
message
|
24
18
|
end
|
25
19
|
end
|
26
20
|
end
|
data/lib/stoplight/version.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples_for 'a generic notifier' do
|
6
|
+
it 'includes Generic' do
|
7
|
+
expect(described_class).to include(Stoplight::Notifier::Generic)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#formatter' do
|
11
|
+
it 'is initially the default' do
|
12
|
+
formatter = nil
|
13
|
+
expect(described_class.new(nil, formatter).formatter)
|
14
|
+
.to eql(Stoplight::Default::FORMATTER)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'reads the formatter' do
|
18
|
+
formatter = proc {}
|
19
|
+
expect(described_class.new(nil, formatter).formatter)
|
20
|
+
.to eql(formatter)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#notify' do
|
25
|
+
let(:light) { Stoplight::Light.new(name, &code) }
|
26
|
+
let(:name) { ('a'..'z').to_a.shuffle.join }
|
27
|
+
let(:code) { -> {} }
|
28
|
+
let(:from_color) { Stoplight::Color::GREEN }
|
29
|
+
let(:to_color) { Stoplight::Color::RED }
|
30
|
+
let(:notifier) { described_class.new(double.as_null_object) }
|
31
|
+
|
32
|
+
it 'returns the message' do
|
33
|
+
error = nil
|
34
|
+
expect(notifier.notify(light, from_color, to_color, error))
|
35
|
+
.to eql(notifier.formatter.call(light, from_color, to_color, error))
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'returns the message with an error' do
|
39
|
+
error = ZeroDivisionError.new('divided by 0')
|
40
|
+
expect(notifier.notify(light, from_color, to_color, error))
|
41
|
+
.to eql(notifier.formatter.call(light, from_color, to_color, error))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec.describe Stoplight::Notifier::Generic do
|
47
|
+
it 'is a module' do
|
48
|
+
expect(described_class).to be_a(Module)
|
49
|
+
end
|
50
|
+
end
|
@@ -1,29 +1,19 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
|
+
require 'stringio'
|
4
5
|
|
5
6
|
RSpec.describe Stoplight::Notifier::IO do
|
7
|
+
it_behaves_like 'a generic notifier'
|
8
|
+
|
6
9
|
it 'is a class' do
|
7
|
-
expect(described_class).to be_a(
|
10
|
+
expect(described_class).to be_a(Class)
|
8
11
|
end
|
9
12
|
|
10
13
|
it 'is a subclass of Base' do
|
11
14
|
expect(described_class).to be < Stoplight::Notifier::Base
|
12
15
|
end
|
13
16
|
|
14
|
-
describe '#formatter' do
|
15
|
-
it 'is initially the default' do
|
16
|
-
expect(described_class.new(nil).formatter)
|
17
|
-
.to eql(Stoplight::Default::FORMATTER)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'reads the formatter' do
|
21
|
-
formatter = proc {}
|
22
|
-
expect(described_class.new(nil, formatter).formatter)
|
23
|
-
.to eql(formatter)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
17
|
describe '#io' do
|
28
18
|
it 'reads the IO' do
|
29
19
|
io = StringIO.new
|
@@ -40,18 +30,6 @@ RSpec.describe Stoplight::Notifier::IO do
|
|
40
30
|
let(:notifier) { described_class.new(io) }
|
41
31
|
let(:io) { StringIO.new }
|
42
32
|
|
43
|
-
it 'returns the message' do
|
44
|
-
error = nil
|
45
|
-
expect(notifier.notify(light, from_color, to_color, error))
|
46
|
-
.to eql(notifier.formatter.call(light, from_color, to_color, error))
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns the message with an error' do
|
50
|
-
error = ZeroDivisionError.new('divided by 0')
|
51
|
-
expect(notifier.notify(light, from_color, to_color, error))
|
52
|
-
.to eql(notifier.formatter.call(light, from_color, to_color, error))
|
53
|
-
end
|
54
|
-
|
55
33
|
it 'writes the message' do
|
56
34
|
error = nil
|
57
35
|
notifier.notify(light, from_color, to_color, error)
|
@@ -4,23 +4,17 @@ require 'spec_helper'
|
|
4
4
|
require 'slack-notifier'
|
5
5
|
|
6
6
|
RSpec.describe Stoplight::Notifier::Slack do
|
7
|
-
|
8
|
-
expect(described_class).to be < Stoplight::Notifier::Base
|
9
|
-
end
|
7
|
+
it_behaves_like 'a generic notifier'
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
.to eql(Stoplight::Default::FORMATTER)
|
15
|
-
end
|
9
|
+
it 'is a class' do
|
10
|
+
expect(described_class).to be_a(Class)
|
11
|
+
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
expect(described_class.new(nil, formatter).formatter).to eql(formatter)
|
20
|
-
end
|
13
|
+
it 'is a subclass of Base' do
|
14
|
+
expect(described_class).to be < Stoplight::Notifier::Base
|
21
15
|
end
|
22
16
|
|
23
|
-
describe '#
|
17
|
+
describe '#slack' do
|
24
18
|
it 'reads Slack::Notifier client' do
|
25
19
|
slack = Slack::Notifier.new('WEBHOOK_URL')
|
26
20
|
expect(described_class.new(slack).slack).to eql(slack)
|
@@ -34,22 +28,13 @@ RSpec.describe Stoplight::Notifier::Slack do
|
|
34
28
|
let(:from_color) { Stoplight::Color::GREEN }
|
35
29
|
let(:to_color) { Stoplight::Color::RED }
|
36
30
|
let(:notifier) { described_class.new(slack) }
|
37
|
-
let(:slack) { double(Slack::Notifier) }
|
38
|
-
|
39
|
-
before do
|
40
|
-
expect(slack).to receive(:ping).with(kind_of(String))
|
41
|
-
end
|
31
|
+
let(:slack) { double(Slack::Notifier).as_null_object }
|
42
32
|
|
43
|
-
it '
|
33
|
+
it 'pings Slack' do
|
44
34
|
error = nil
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
it 'returns the message with an error' do
|
50
|
-
error = ZeroDivisionError.new('divided by 0')
|
51
|
-
expect(notifier.notify(light, from_color, to_color, error))
|
52
|
-
.to eql(notifier.formatter.call(light, from_color, to_color, error))
|
35
|
+
message = notifier.formatter.call(light, from_color, to_color, error)
|
36
|
+
expect(slack).to receive(:ping).with(message)
|
37
|
+
notifier.notify(light, from_color, to_color, error)
|
53
38
|
end
|
54
39
|
end
|
55
40
|
end
|
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.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Desautels
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-07-
|
13
|
+
date: 2015-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: benchmark-ips
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- lib/stoplight/light/runnable.rb
|
234
234
|
- lib/stoplight/notifier.rb
|
235
235
|
- lib/stoplight/notifier/base.rb
|
236
|
+
- lib/stoplight/notifier/generic.rb
|
236
237
|
- lib/stoplight/notifier/hip_chat.rb
|
237
238
|
- lib/stoplight/notifier/io.rb
|
238
239
|
- lib/stoplight/notifier/slack.rb
|
@@ -250,6 +251,7 @@ files:
|
|
250
251
|
- spec/stoplight/light/runnable_spec.rb
|
251
252
|
- spec/stoplight/light_spec.rb
|
252
253
|
- spec/stoplight/notifier/base_spec.rb
|
254
|
+
- spec/stoplight/notifier/generic_spec.rb
|
253
255
|
- spec/stoplight/notifier/hip_chat_spec.rb
|
254
256
|
- spec/stoplight/notifier/io_spec.rb
|
255
257
|
- spec/stoplight/notifier/slack_spec.rb
|
@@ -277,7 +279,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
277
279
|
version: '0'
|
278
280
|
requirements: []
|
279
281
|
rubyforge_project:
|
280
|
-
rubygems_version: 2.4.
|
282
|
+
rubygems_version: 2.4.5
|
281
283
|
signing_key:
|
282
284
|
specification_version: 4
|
283
285
|
summary: Traffic control for code.
|
@@ -294,6 +296,7 @@ test_files:
|
|
294
296
|
- spec/stoplight/light/runnable_spec.rb
|
295
297
|
- spec/stoplight/light_spec.rb
|
296
298
|
- spec/stoplight/notifier/base_spec.rb
|
299
|
+
- spec/stoplight/notifier/generic_spec.rb
|
297
300
|
- spec/stoplight/notifier/hip_chat_spec.rb
|
298
301
|
- spec/stoplight/notifier/io_spec.rb
|
299
302
|
- spec/stoplight/notifier/slack_spec.rb
|