stoplight 4.0.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0194283983ed6568bca930b6640a7d397dd06e779d921e8bd169cb6a8e743448'
4
- data.tar.gz: 9b68b81b05c15cbed7885d8f10a042c0e0ecacafacb0fe6e621e3c124007d74e
3
+ metadata.gz: dec6c43881dfde16456ffa319f2f543f2c507dbdd760c5adf7ddb155dfa9292b
4
+ data.tar.gz: b3609d6233f73d9a2c4a5474ef291d76fe9ccd906267cf9d831b22a040c67d1f
5
5
  SHA512:
6
- metadata.gz: 64c7f5d19bb00b46f9908d938a120c475f1fd60e481e58400c49360dae260bd6c83690e61f34362a20dea0b3b955f4f9b9d76030b8ccbb7c788fd7a531ad395b
7
- data.tar.gz: e48e470e7f72d811852df5576b132a11f6f69dedf711cf371c9cfbc4dc1a4600f217b147ba53c9313a8863a06aaef88e279d3cd5f7e8ff51bd69c731123b1093
6
+ metadata.gz: 536ab89edb5ce429274c1f54f6718ac1a82968bb10a75a5c8d44b4dfacaf5a1a37a6f9aaac2c2c91f0b0849e149df6696e1d29373f40280ab860c3ada08e357f
7
+ data.tar.gz: b59267822e4ead10f8675e08c6fa16bf76c4b430a0c3c0fa9d69eb42a4df8387e22a36135b6c5d76a5f76b4e002db052937af311ee160b919a0c85a027341564
data/README.md CHANGED
@@ -9,8 +9,9 @@ Stoplight is traffic control for code. It's an implementation of the circuit
9
9
  breaker pattern in Ruby.
10
10
 
11
11
  ---
12
- :warning: You're browsing the documentation of the not realized version. You can find the documentation
13
- for the most recent version 3.0.1 [here](https://github.com/bolshakov/stoplight/tree/v3.0.1).
12
+
13
+ :warning:️ You're currently browsing the documentation for Stoplight 4.x. If you're looking for
14
+ the documentation of the previous version 3.x, you can find it [here](https://github.com/bolshakov/stoplight/tree/release/v3.x).
14
15
 
15
16
  Does your code use unreliable systems, like a flaky database or a spotty web
16
17
  service? Wrap calls to those up in stoplights to prevent them from affecting
@@ -38,7 +39,7 @@ Check out [stoplight-admin][] for controlling your stoplights.
38
39
  - [Advanced Usage](#advanced-usage)
39
40
  - [Locking](#locking)
40
41
  - [Testing](#testing)
41
- - [Maintenance Policy][#maintenance-policy]
42
+ - [Maintenance Policy](#maintenance-policy)
42
43
  - [Credits](#credits)
43
44
 
44
45
  ## Installation
@@ -360,6 +361,7 @@ Stoplight.default_notifiers += [notifier]
360
361
  #### Community-supported Notifiers
361
362
 
362
363
  * [stoplight-sentry]
364
+ * [stoplight-honeybadger](https://github.com/qoqa/stoplight-honeybadger)
363
365
 
364
366
  You you want to implement your own notifier, the following section contains all the required information.
365
367
 
@@ -30,6 +30,8 @@ module Stoplight
30
30
  def_delegator :build, :with_error_handler
31
31
  def_delegator :build, :with_fallback
32
32
  def_delegator :build, :color
33
+ def_delegator :build, :name
34
+ def_delegator :build, :state
33
35
  def_delegator :build, :run
34
36
  def_delegator :build, :lock
35
37
  def_delegator :build, :unlock
@@ -39,6 +39,16 @@ module Stoplight
39
39
  raise NotImplementedError
40
40
  end
41
41
 
42
+ # @return [String] one of +locked_green+, +locked_red+, and +unlocked+
43
+ def state
44
+ raise NotImplementedError
45
+ end
46
+
47
+ # @return [String] the light's name
48
+ def name
49
+ raise NotImplementedError
50
+ end
51
+
42
52
  # Returns current color:
43
53
  # * +Stoplight::Color::GREEN+ -- circuit breaker is closed
44
54
  # * +Stoplight::Color::RED+ -- circuit breaker is open
@@ -42,7 +42,7 @@ module Stoplight
42
42
  end
43
43
 
44
44
  def clear_failures(light)
45
- synchronize { @failures.delete(light.name) }
45
+ synchronize { @failures.delete(light.name) || [] }
46
46
  end
47
47
 
48
48
  def get_state(light)
@@ -3,6 +3,12 @@
3
3
  module Stoplight
4
4
  class Light
5
5
  module Runnable # rubocop:disable Style/Documentation
6
+ # @return [String]
7
+ def state
8
+ _, state = failures_and_state
9
+ state
10
+ end
11
+
6
12
  # @return [String]
7
13
  def color
8
14
  failures, state = failures_and_state
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stoplight
4
- VERSION = Gem::Version.new('4.0.0')
4
+ VERSION = Gem::Version.new('4.1.1')
5
5
  end
@@ -21,6 +21,14 @@ RSpec.describe Stoplight::CircuitBreaker do
21
21
  expect { circuit_breaker.color }.to raise_error(NotImplementedError)
22
22
  end
23
23
 
24
+ specify '#state' do
25
+ expect { circuit_breaker.state }.to raise_error(NotImplementedError)
26
+ end
27
+
28
+ specify '#name' do
29
+ expect { circuit_breaker.name }.to raise_error(NotImplementedError)
30
+ end
31
+
24
32
  specify '#run' do
25
33
  expect { circuit_breaker.run {} }.to raise_error(NotImplementedError)
26
34
  end
@@ -23,6 +23,7 @@ RSpec.describe Stoplight::Light::Runnable, :redis do
23
23
  context 'with memory data store' do
24
24
  let(:data_store) { Stoplight::DataStore::Memory.new }
25
25
 
26
+ it_behaves_like 'Stoplight::Light::Runnable#state'
26
27
  it_behaves_like 'Stoplight::Light::Runnable#color'
27
28
  it_behaves_like 'Stoplight::Light::Runnable#run'
28
29
  end
@@ -30,6 +31,7 @@ RSpec.describe Stoplight::Light::Runnable, :redis do
30
31
  context 'with redis data store', :redis do
31
32
  let(:data_store) { Stoplight::DataStore::Redis.new(redis) }
32
33
 
34
+ it_behaves_like 'Stoplight::Light::Runnable#state'
33
35
  it_behaves_like 'Stoplight::Light::Runnable#color'
34
36
  it_behaves_like 'Stoplight::Light::Runnable#run'
35
37
  end
@@ -9,6 +9,12 @@ RSpec.shared_examples 'Stoplight::DataStore::Base#clear_failures' do
9
9
  expect(data_store.clear_failures(light)).to contain_exactly(failure)
10
10
  end
11
11
 
12
+ it 'returns an empty array when there are no failures' do
13
+ data_store.clear_failures(light)
14
+
15
+ expect(data_store.clear_failures(light)).to be_empty
16
+ end
17
+
12
18
  it 'clears the failures' do
13
19
  expect do
14
20
  data_store.clear_failures(light)
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples 'Stoplight::Light::Runnable#state' do
4
+ subject(:light) { Stoplight::Light.new(name) }
5
+
6
+ let(:name) { random_string }
7
+
8
+ it 'is initially unlocked' do
9
+ expect(light.state).to eql(Stoplight::State::UNLOCKED)
10
+ end
11
+
12
+ context 'when its locked green' do
13
+ before do
14
+ light.data_store.set_state(light, Stoplight::State::LOCKED_GREEN)
15
+ end
16
+
17
+ it 'is locked green' do
18
+ expect(light.state).to eql(Stoplight::State::LOCKED_GREEN)
19
+ end
20
+ end
21
+
22
+ context 'when its locked red' do
23
+ before do
24
+ light.data_store.set_state(light, Stoplight::State::LOCKED_RED)
25
+ end
26
+
27
+ it 'is locked red' do
28
+ expect(light.state).to eql(Stoplight::State::LOCKED_RED)
29
+ end
30
+ end
31
+ end
@@ -2,3 +2,4 @@
2
2
 
3
3
  require_relative 'runnable/color'
4
4
  require_relative 'runnable/run'
5
+ require_relative 'runnable/state'
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: 4.0.0
4
+ version: 4.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: 2023-08-18 00:00:00.000000000 Z
13
+ date: 2025-02-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: redlock
@@ -103,6 +103,7 @@ files:
103
103
  - spec/support/light/runnable.rb
104
104
  - spec/support/light/runnable/color.rb
105
105
  - spec/support/light/runnable/run.rb
106
+ - spec/support/light/runnable/state.rb
106
107
  homepage: https://github.com/bolshakov/stoplight
107
108
  licenses:
108
109
  - MIT
@@ -122,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  requirements: []
125
- rubygems_version: 3.3.7
126
+ rubygems_version: 3.5.18
126
127
  signing_key:
127
128
  specification_version: 4
128
129
  summary: Traffic control for code.
@@ -165,4 +166,5 @@ test_files:
165
166
  - spec/support/exception_helpers.rb
166
167
  - spec/support/light/runnable/color.rb
167
168
  - spec/support/light/runnable/run.rb
169
+ - spec/support/light/runnable/state.rb
168
170
  - spec/support/light/runnable.rb