simple_circuit_breaker 0.2.0 → 0.2.1

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MGZjYzllMjEyYTA3YzliM2IxNjE3NGQ0MGQ2N2U4OGY2NWFhYjk5Yg==
5
+ data.tar.gz: !binary |-
6
+ ZDMzMWYzMDUxNDViYmVhMDg1MTQ4NWExMTFjNzk4NDQzNGY2MmM4MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NGM2NTI3YmJhNDFlY2U2ZDQ4ZWIyYWE4ZmJhOTlhMDQwMmZiOGUyODU4ZGU2
10
+ MTgyMWRhYTNjNWIzNjA3OTE4ZDQ2MTZiNjM5NTdlZDJlMTQ3YjE3YTJhMDcz
11
+ YmEzOWY5MzkyMDEzN2I1ZGIyMjAwNmFmOTA4MTBlMzE3NGYxMDQ=
12
+ data.tar.gz: !binary |-
13
+ YmQyYTRjZWU5MjVjNWEzYThjNGJjYzU1ODY5ZTJiZGZjZDZjNmVmMDlhOGJi
14
+ NmFkYjk1M2Y2ZmM0NTg1OWFmODY4ZTY2ZGJhN2NlMmUyNzM1OTljNzk1Nzkw
15
+ ZGE1NzgxOGM2YWQ4MjA2MDZhZTJmMTUxNDMzMDExOTI4MTZiYmE=
@@ -1,5 +1,5 @@
1
1
  class SimpleCircuitBreaker
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
 
4
4
  class CircuitOpenError < StandardError
5
5
  end
@@ -24,7 +24,7 @@ protected
24
24
 
25
25
  def execute(exceptions, &block)
26
26
  begin
27
- yield.tap { success! }
27
+ yield.tap { reset! }
28
28
  rescue Exception => exception
29
29
  if exceptions.empty? || exceptions.include?(exception.class)
30
30
  fail!
@@ -33,12 +33,6 @@ protected
33
33
  end
34
34
  end
35
35
 
36
- def success!
37
- if @state == :half_open
38
- reset!
39
- end
40
- end
41
-
42
36
  def fail!
43
37
  @failures += 1
44
38
  if @failures >= @failure_threshold
@@ -53,16 +47,7 @@ protected
53
47
  end
54
48
 
55
49
  def tripped?
56
- @state != :closed && !try_to_close
57
- end
58
-
59
- def try_to_close
60
- if timeout_exceeded?
61
- @state = :half_open
62
- true
63
- else
64
- false
65
- end
50
+ @state == :open && !timeout_exceeded?
66
51
  end
67
52
 
68
53
  def timeout_exceeded?
@@ -73,6 +73,16 @@ describe SimpleCircuitBreaker do
73
73
  end
74
74
  end
75
75
  end
76
+
77
+ it 'doesn\'t open after 3 non-consecutive failures for handled exception' do
78
+ 4.times do
79
+ begin
80
+ @breaker.handle(RuntimeError) {}
81
+ @breaker.handle(RuntimeError) { raise RuntimeError }
82
+ rescue RuntimeError
83
+ end
84
+ end
85
+ end
76
86
  end
77
87
 
78
88
  describe 'opened circuit' do
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_circuit_breaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
5
- prerelease:
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Julius Volz
@@ -10,7 +9,7 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2014-01-19 00:00:00.000000000 Z
14
13
  dependencies: []
15
14
  description: Simple Ruby implementation of the Circuit Breaker design pattern
16
15
  email: julius@soundcloud.com ts@soundcloud.com
@@ -27,27 +26,27 @@ files:
27
26
  - test/simple_circuit_breaker_test.rb
28
27
  homepage: http://github.com/soundcloud/simple_circuit_breaker
29
28
  licenses: []
29
+ metadata: {}
30
30
  post_install_message:
31
31
  rdoc_options: []
32
32
  require_paths:
33
33
  - lib
34
34
  required_ruby_version: !ruby/object:Gem::Requirement
35
- none: false
36
35
  requirements:
37
36
  - - ! '>='
38
37
  - !ruby/object:Gem::Version
39
38
  version: '1.9'
40
39
  required_rubygems_version: !ruby/object:Gem::Requirement
41
- none: false
42
40
  requirements:
43
41
  - - ! '>='
44
42
  - !ruby/object:Gem::Version
45
43
  version: '0'
46
44
  requirements: []
47
45
  rubyforge_project:
48
- rubygems_version: 1.8.24
46
+ rubygems_version: 2.1.11
49
47
  signing_key:
50
- specification_version: 3
48
+ specification_version: 4
51
49
  summary: Ruby Circuit Breaker implementation
52
50
  test_files:
53
51
  - test/simple_circuit_breaker_test.rb
52
+ has_rdoc: