stoplight 0.4.0 → 0.4.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
  SHA1:
3
- metadata.gz: 817cede2460b3309d9d6b2eed1e2eb5fd7c089e0
4
- data.tar.gz: 7c5b0b24c68c0d4b63bdcf285dc97d0a67b2eedb
3
+ metadata.gz: 314c63808a80e427881c2d09152f74e68f4ffd37
4
+ data.tar.gz: 67ab9ca03f20512f5b119b95eec17494d7fdf726
5
5
  SHA512:
6
- metadata.gz: 128a58ba2d5667ca408a05696defb2cb8152a20c3f4f28e641d18e4ca91730b5209fb8f376fcff019989984fb49fdb75bdc9fbb24a8485e390e41b79799cbb37
7
- data.tar.gz: b6766506606eda2a21886582ea626517a2f9d01d0b0967a63b323d67e58103167780ec91ff0ce018d9d341adaf07bca5261e8cc223a78dc06688391e58c1cf4c
6
+ metadata.gz: 5a758d0cd6beeb2b0c034f424ec4b4b2fc1fe72f11a7eb598fe195e408437ec6ba3dd95aa9b29554d5a9e8a0727fabbfdc46aade4a7c1674cf457467459032c5
7
+ data.tar.gz: 50eb0565526a389406422fdca3b93a9ce4923bd7ab7e50aa558b976ca09ed56ee976c9bcc3fc4b0f72c6a28290964e4a676d1c6dbb741ae45fed26b9f30619ab
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.1 (2014-10-03)
4
+
5
+ - Fixed a bug that caused green to red notifications to sometimes not be sent.
6
+
3
7
  ## v0.4.0 (2014-09-17)
4
8
 
5
9
  - Made stoplights handle failing notifiers by logging the failure to standard
data/README.md CHANGED
@@ -33,7 +33,7 @@ Check out [stoplight-admin][12] for controlling your stoplights.
33
33
  Add it to your Gemfile:
34
34
 
35
35
  ``` rb
36
- gem 'stoplight', '~> 0.4.0'
36
+ gem 'stoplight', '~> 0.4.1'
37
37
  ```
38
38
 
39
39
  Or install it manually:
@@ -8,23 +8,25 @@ module Stoplight
8
8
  fail NotImplementedError
9
9
  end
10
10
 
11
- # @return [nil]
12
11
  def clear_stale
13
12
  fail NotImplementedError
14
13
  end
15
14
 
16
15
  # @param _name [String]
17
- # @return [nil]
18
16
  def clear(_name)
19
17
  fail NotImplementedError
20
18
  end
21
19
 
22
20
  # @param _name [String]
23
- # @return [nil]
24
21
  def sync(_name)
25
22
  fail NotImplementedError
26
23
  end
27
24
 
25
+ # @param _name [String]
26
+ def greenify(_name)
27
+ fail NotImplementedError
28
+ end
29
+
28
30
  # @group Colors
29
31
 
30
32
  # @param name [String]
@@ -72,7 +74,6 @@ module Stoplight
72
74
  end
73
75
 
74
76
  # @param _name [String]
75
- # @return [nil]
76
77
  def clear_attempts(_name)
77
78
  fail NotImplementedError
78
79
  end
@@ -93,7 +94,6 @@ module Stoplight
93
94
  end
94
95
 
95
96
  # @param _name [String]
96
- # @return [nil]
97
97
  def clear_failures(_name)
98
98
  fail NotImplementedError
99
99
  end
@@ -114,7 +114,6 @@ module Stoplight
114
114
  end
115
115
 
116
116
  # @param _name [String]
117
- # @return [nil]
118
117
  def clear_state(_name)
119
118
  fail NotImplementedError
120
119
  end
@@ -135,7 +134,6 @@ module Stoplight
135
134
  end
136
135
 
137
136
  # @param _name [String]
138
- # @return [nil]
139
137
  def clear_threshold(_name)
140
138
  fail NotImplementedError
141
139
  end
@@ -156,7 +154,6 @@ module Stoplight
156
154
  end
157
155
 
158
156
  # @param _name [String]
159
- # @return [nil]
160
157
  def clear_timeout(_name)
161
158
  fail NotImplementedError
162
159
  end
@@ -15,7 +15,6 @@ module Stoplight
15
15
  names
16
16
  .select { |name| get_failures(name).empty? }
17
17
  .each { |name| clear(name) }
18
- nil
19
18
  end
20
19
 
21
20
  def clear(name)
@@ -28,7 +27,11 @@ module Stoplight
28
27
 
29
28
  def sync(name)
30
29
  set_threshold(name, get_threshold(name))
31
- nil
30
+ end
31
+
32
+ def greenify(name)
33
+ clear_attempts(name)
34
+ clear_failures(name)
32
35
  end
33
36
 
34
37
  def get_color(name)
@@ -49,7 +52,6 @@ module Stoplight
49
52
 
50
53
  def clear_attempts(name)
51
54
  attempts.delete(name)
52
- nil
53
55
  end
54
56
 
55
57
  def get_failures(name)
@@ -65,7 +67,6 @@ module Stoplight
65
67
 
66
68
  def clear_failures(name)
67
69
  @data.delete(DataStore.failures_key(name))
68
- nil
69
70
  end
70
71
 
71
72
  def get_state(name)
@@ -79,7 +80,6 @@ module Stoplight
79
80
 
80
81
  def clear_state(name)
81
82
  states.delete(name)
82
- nil
83
83
  end
84
84
 
85
85
  def get_threshold(name)
@@ -93,7 +93,6 @@ module Stoplight
93
93
 
94
94
  def clear_threshold(name)
95
95
  thresholds.delete(name)
96
- nil
97
96
  end
98
97
 
99
98
  def get_timeout(name)
@@ -107,7 +106,6 @@ module Stoplight
107
106
 
108
107
  def clear_timeout(name)
109
108
  timeouts.delete(name)
110
- nil
111
109
  end
112
110
 
113
111
  private
@@ -18,7 +18,6 @@ module Stoplight
18
18
  names
19
19
  .select { |name| get_failures(name).empty? }
20
20
  .each { |name| clear(name) }
21
- nil
22
21
  end
23
22
 
24
23
  def clear(name)
@@ -29,19 +28,23 @@ module Stoplight
29
28
  clear_threshold(name)
30
29
  clear_timeout(name)
31
30
  end
32
-
33
- nil
34
31
  end
35
32
 
36
33
  def sync(name)
37
34
  threshold = @redis.hget(DataStore.thresholds_key, name)
38
35
  threshold = normalize_threshold(threshold)
39
36
  @redis.hset(DataStore.thresholds_key, name, threshold)
40
- nil
41
37
  rescue ::Redis::BaseError => error
42
38
  raise Error::BadDataStore, error
43
39
  end
44
40
 
41
+ def greenify(name)
42
+ @redis.pipelined do
43
+ clear_attempts(name)
44
+ clear_failures(name)
45
+ end
46
+ end
47
+
45
48
  def get_color(name)
46
49
  DataStore.colorize(*colorize_args(name))
47
50
  end
@@ -56,7 +59,6 @@ module Stoplight
56
59
 
57
60
  def clear_attempts(name)
58
61
  @redis.hdel(DataStore.attempts_key, name)
59
- nil
60
62
  end
61
63
 
62
64
  def get_failures(name)
@@ -71,7 +73,6 @@ module Stoplight
71
73
 
72
74
  def clear_failures(name)
73
75
  @redis.del(DataStore.failures_key(name))
74
- nil
75
76
  end
76
77
 
77
78
  def get_state(name)
@@ -86,7 +87,6 @@ module Stoplight
86
87
 
87
88
  def clear_state(name)
88
89
  @redis.hdel(DataStore.states_key, name)
89
- nil
90
90
  end
91
91
 
92
92
  def get_threshold(name)
@@ -101,7 +101,6 @@ module Stoplight
101
101
 
102
102
  def clear_threshold(name)
103
103
  @redis.hdel(DataStore.thresholds_key, name)
104
- nil
105
104
  end
106
105
 
107
106
  def get_timeout(name)
@@ -116,7 +115,6 @@ module Stoplight
116
115
 
117
116
  def clear_timeout(name)
118
117
  @redis.hdel(DataStore.timeouts_key, name)
119
- nil
120
118
  end
121
119
 
122
120
  private
@@ -110,7 +110,7 @@ module Stoplight
110
110
  private
111
111
 
112
112
  def run_green
113
- code.call.tap { Stoplight.data_store.clear_failures(name) }
113
+ code.call.tap { Stoplight.data_store.greenify(name) }
114
114
  rescue => error
115
115
  handle_error(error)
116
116
  raise
@@ -129,7 +129,7 @@ module Stoplight
129
129
 
130
130
  def handle_error(error)
131
131
  if error_allowed?(error)
132
- Stoplight.data_store.clear_failures(name)
132
+ Stoplight.data_store.greenify(name)
133
133
  else
134
134
  Stoplight.data_store.record_failure(name, Failure.create(error))
135
135
  end
data/lib/stoplight.rb CHANGED
@@ -14,7 +14,7 @@ require 'stoplight/notifier/io'
14
14
 
15
15
  module Stoplight
16
16
  # @return [Gem::Version]
17
- VERSION = Gem::Version.new('0.4.0')
17
+ VERSION = Gem::Version.new('0.4.1')
18
18
 
19
19
  @data_store = DataStore::Memory.new
20
20
  @notifiers = [Notifier::IO.new($stderr)]
@@ -10,6 +10,7 @@ describe Stoplight::DataStore::Base do
10
10
  clear_stale
11
11
  clear
12
12
  sync
13
+ greenify
13
14
  green?
14
15
  yellow?
15
16
  red?
@@ -111,6 +111,28 @@ describe Stoplight::Light do
111
111
  end
112
112
  end
113
113
 
114
+ context 'conditionally failing' do
115
+ let(:code_result) { fail error if @fail }
116
+ let(:name) { 'failing' }
117
+
118
+ it 'clears the attempts' do
119
+ @fail = true
120
+ light.threshold.succ.times do
121
+ begin
122
+ light.run
123
+ rescue error_class, Stoplight::Error::RedLight
124
+ nil
125
+ end
126
+ end
127
+
128
+ @fail = false
129
+ Stoplight.data_store.set_timeout(light.name, 0)
130
+ light.run
131
+
132
+ expect(Stoplight.data_store.get_attempts(light.name)).to eq(0)
133
+ end
134
+ end
135
+
114
136
  context 'with Redis' do
115
137
  let(:data_store) { Stoplight::DataStore::Redis.new(redis) }
116
138
  let(:redis) { Redis.new }
@@ -12,28 +12,20 @@ shared_examples_for 'a data store' do
12
12
  let(:timeout) { rand(100) }
13
13
 
14
14
  it { expect(data_store.names).to eql([]) }
15
- it { expect(data_store.clear_stale).to eql(nil) }
16
- it { expect(data_store.clear(name)).to eql(nil) }
17
- it { expect(data_store.sync(name)).to eql(nil) }
18
15
  it { expect(data_store.get_color(name)).to eql(Stoplight::DataStore::COLOR_GREEN) }
19
16
  it { expect(data_store.green?(name)).to eql(true) }
20
17
  it { expect(data_store.yellow?(name)).to eql(false) }
21
18
  it { expect(data_store.red?(name)).to eql(false) }
22
19
  it { expect(data_store.get_attempts(name)).to eql(Stoplight::DataStore::DEFAULT_ATTEMPTS) }
23
20
  it { expect(data_store.record_attempt(name)).to eql(1) }
24
- it { expect(data_store.clear_attempts(name)).to eql(nil) }
25
21
  it { expect(data_store.get_failures(name)).to eql(Stoplight::DataStore::DEFAULT_FAILURES) }
26
22
  it { expect(data_store.record_failure(name, failure)).to eql(failure) }
27
- it { expect(data_store.clear_failures(name)).to eql(nil) }
28
23
  it { expect(data_store.get_state(name)).to eql(Stoplight::DataStore::DEFAULT_STATE) }
29
24
  it { expect(data_store.set_state(name, state)).to eql(state) }
30
- it { expect(data_store.clear_state(name)).to eql(nil) }
31
25
  it { expect(data_store.get_threshold(name)).to eql(Stoplight::DataStore::DEFAULT_THRESHOLD) }
32
26
  it { expect(data_store.set_threshold(name, threshold)).to eql(threshold) }
33
- it { expect(data_store.clear_threshold(name)).to eql(nil) }
34
27
  it { expect(data_store.get_timeout(name)).to eql(Stoplight::DataStore::DEFAULT_TIMEOUT) }
35
28
  it { expect(data_store.set_timeout(name, timeout)).to eql(timeout) }
36
- it { expect(data_store.clear_timeout(name)).to eql(nil) }
37
29
 
38
30
  it 'clears stale lights' do
39
31
  data_store.sync(name)
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: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Desautels
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-17 00:00:00.000000000 Z
12
+ date: 2014-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: benchmark-ips