circuit_breakage 0.2.2 → 0.2.3

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: d643902ba2ada91222c75da26be3426d55eb5db4
4
- data.tar.gz: f8f3a7c49ec02514e4bd54d54f401c9d257e6430
3
+ metadata.gz: bf00e430eba8f24feacafd2a94ebfc2e9ce53737
4
+ data.tar.gz: d6550c42f12736a6a87a6059df53ba2315fa320b
5
5
  SHA512:
6
- metadata.gz: b539db6b88213831b37ec97b00c317b088a87558130c6f2533a2360bae3b3e9b1139a3725be313e88c46f27b4eba55fb9b49c23efe5604a17694c5d2690a587f
7
- data.tar.gz: 78ab5583212c28a9368168cc4425c96b6ccf44b2afe5bfa791aa93846bbff3bb130ed942d4ee919c6f6d47fd64fc547ec040816cd7e31189578b6fcee49ea797
6
+ metadata.gz: 5752657e3fd2e10342190cbfab8539068087cb145a07070f02091dbdaa0da50249afede7656def46eef30dd524f242041e7c5ff0bc8573ef56a5aae509b0a79c
7
+ data.tar.gz: a51e540148c42f4de8d3008b40a14b77ae680010ae4d64f4f404b04cb0793822d9e850c63f29e1b82c45e4967a571aaf0920e522ecf9f5e07ce6293b9fb39699
data/README.md CHANGED
@@ -10,20 +10,20 @@ description of the pattern.
10
10
 
11
11
  ## Usage
12
12
 
13
- ### Normal Boring Circuit Breakers
13
+ ### Simple Example
14
14
 
15
15
  ```ruby
16
- block = ->(*args) do
16
+ proc = ->(*args) do
17
17
  # Some dangerous thing.
18
18
  end
19
19
 
20
- breaker = CircuitBreakage::Breaker.new(block)
21
- breaker.failure_threshold = 3 # only 3 failures before tripping circuit
22
- breaker.duration = 10 # 10 seconds before retry
23
- breaker.timeout = 0.5 # 500 milliseconds allowed before auto-fail
20
+ breaker = CircuitBreakage::Breaker.new(proc)
21
+ breaker.failure_threshold = 3 # only 3 failures before tripping circuit
22
+ breaker.duration = 10 # 10 seconds before retry
23
+ breaker.timeout = 0.5 # 500 milliseconds allowed before auto-fail
24
24
 
25
25
  begin
26
- breaker.call(*some_args) # args are passed through to block
26
+ breaker.call(*some_args) # args are passed through to the proc
27
27
  rescue CircuitBreakage::CircuitOpen
28
28
  puts "Too many recent failures!"
29
29
  rescue CircuitBreakage::CircuitTimeout
@@ -31,9 +31,58 @@ rescue CircuitBreakage::CircuitTimeout
31
31
  end
32
32
  ```
33
33
 
34
- A "failure" in this context means that the block either raised an exception or
34
+ A "failure" in this context means that the proc either raised an exception or
35
35
  timed out.
36
36
 
37
+ ### Slightly More Complex Example in Rails
38
+
39
+ This example shows one way you might choose to wrap a remote service call in a
40
+ Rails app.
41
+
42
+ ```ruby
43
+ # in your controller
44
+ class MyController
45
+ def show
46
+ widget_client = WidgetClient.new
47
+ @widgets = widget_client.get_widget(id)
48
+ end
49
+ end
50
+
51
+ # in lib/widget_client.rb
52
+ class WidgetClient
53
+ class << self
54
+ def breaker
55
+ if @breaker.nil?
56
+ @breaker = CircuitBreakage::Breaker.new method(:do_get_widget)
57
+ @breaker.failure_threshold = 3
58
+ @breaker.duration = 10
59
+ @breaker.timeout = 0.5
60
+ end
61
+
62
+ return @breaker
63
+ end
64
+
65
+ def do_get_widget(id)
66
+ # Do the remote service call here.
67
+ end
68
+ end
69
+
70
+ def get_widget(id)
71
+ class.breaker.call(id)
72
+ end
73
+ end
74
+ ```
75
+
76
+ This makes it easy to control all calls to the remote service with a single
77
+ breaker. This way, they are all tripped and reset together, even if the service
78
+ is called by several different parts of your code. Don't forget to handle
79
+ errors somewhere -- probably either the controller or the client library,
80
+ depending on the needs of your code.
81
+
82
+ Note that we've actually used a `Method` object rather than a proc to
83
+ initialize the circuit breaker. That's fine -- breakers will actually work with
84
+ any object that responds to `call`.
85
+
37
86
  ### Redis-Backed "Shared" Circuit Breakers
38
87
 
39
88
  The unique feature of this particular Circuit Breaker gem is that it also
@@ -50,7 +99,7 @@ the retry timer as appropriate.
50
99
  connection = some_redis_connection
51
100
  key = 'my_app/this_operation'
52
101
 
53
- breaker = CircuitBreakage::RedisBackedBreaker.new(connection, key, block)
102
+ breaker = CircuitBreakage::RedisBackedBreaker.new(connection, key, proc)
54
103
  breaker.lock_timeout = 30 # seconds before assuming a locking process has crashed
55
104
 
56
105
  # Everything else is the same as above.
@@ -59,7 +108,7 @@ breaker.lock_timeout = 30 # seconds before assuming a locking process has crash
59
108
  The `lock_timeout` setting is necessary since a process that crashes or is
60
109
  killed might be holding the retry lock. This sets the amount of time other
61
110
  processes will wait before deciding a lock has expired. It should be longer
62
- than the amount of time you expect the block to take to run.
111
+ than the amount of time you expect the proc to take to run.
63
112
 
64
113
  All circuit breakers using the same key and the same Redis instance will share
65
114
  their state . It is strongly recommended that their settings
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["John Hyland"]
10
10
  spec.email = ["john@djspinmonkey.com"]
11
11
  spec.summary = %q{Provides a simple circuit breaker pattern.}
12
- spec.description = %q{Provides a circuit breaker pattern with configurable error tolerance, timeout, breakage duration, and state storage.}
13
- spec.homepage = "https://source.datanerd.us/jhyland/circuit_breakage" # TODO: move to some org
14
- spec.license = "New Relic"
12
+ spec.description = %q{Provides a circuit breaker pattern with optional support for distributed state.}
13
+ spec.homepage = "https://github.com/djspinmonkey/circuit_breakage"
14
+ spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -1,3 +1,3 @@
1
1
  module CircuitBreakage
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circuit_breakage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Hyland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,8 +66,8 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: Provides a circuit breaker pattern with configurable error tolerance,
70
- timeout, breakage duration, and state storage.
69
+ description: Provides a circuit breaker pattern with optional support for distributed
70
+ state.
71
71
  email:
72
72
  - john@djspinmonkey.com
73
73
  executables: []
@@ -88,9 +88,9 @@ files:
88
88
  - spec/breaker_spec.rb
89
89
  - spec/redis_backed_breaker_spec.rb
90
90
  - spec/spec_helper.rb
91
- homepage: https://source.datanerd.us/jhyland/circuit_breakage
91
+ homepage: https://github.com/djspinmonkey/circuit_breakage
92
92
  licenses:
93
- - New Relic
93
+ - MIT
94
94
  metadata: {}
95
95
  post_install_message:
96
96
  rdoc_options: []