Class: Circuitbox
- Inherits:
-
Object
show all
- Defined in:
- lib/circuitbox.rb,
lib/circuitbox/railtie.rb,
lib/circuitbox/version.rb,
lib/circuitbox/notifier.rb,
lib/circuitbox/errors/error.rb,
lib/circuitbox/circuit_breaker.rb,
lib/circuitbox/faraday_middleware.rb,
lib/circuitbox/errors/open_circuit_error.rb,
lib/circuitbox/errors/service_failure_error.rb
Defined Under Namespace
Classes: CircuitBreaker, Error, FaradayMiddleware, Notifier, OpenCircuitError, Railtie, ServiceFailureError
Constant Summary
collapse
- VERSION =
'0.9.0'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Circuitbox.
24
25
26
|
# File 'lib/circuitbox.rb', line 24
def initialize
self.instance_eval(&@@configure) if @@configure
end
|
Instance Attribute Details
#circuit_store ⇒ Object
Returns the value of attribute circuit_store.
17
18
19
|
# File 'lib/circuitbox.rb', line 17
def circuit_store
@circuit_store
end
|
#circuits ⇒ Object
Returns the value of attribute circuits.
17
18
19
|
# File 'lib/circuitbox.rb', line 17
def circuits
@circuits
end
|
#stat_store ⇒ Object
Returns the value of attribute stat_store.
17
18
19
|
# File 'lib/circuitbox.rb', line 17
def stat_store
@stat_store
end
|
Class Method Details
.[](service_identifier, options = {}) ⇒ Object
53
54
55
|
# File 'lib/circuitbox.rb', line 53
def self.[](service_identifier, options = {})
self.circuit(service_identifier, options)
end
|
.circuit(service_identifier, options = {}) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/circuitbox.rb', line 57
def self.circuit(service_identifier, options = {})
service_name = self.parameter_to_service_name(service_identifier)
self.instance.circuits ||= Hash.new
self.instance.circuits[service_name] ||= CircuitBreaker.new(service_name, options)
if block_given?
self.instance.circuits[service_name].run { yield }
else
self.instance.circuits[service_name]
end
end
|
.circuit_store ⇒ Object
37
38
39
|
# File 'lib/circuitbox.rb', line 37
def self.circuit_store
self.instance.circuit_store ||= ActiveSupport::Cache::MemoryStore.new
end
|
.circuit_store=(store) ⇒ Object
41
42
43
|
# File 'lib/circuitbox.rb', line 41
def self.circuit_store=(store)
self.instance.circuit_store = store
end
|
28
29
30
|
# File 'lib/circuitbox.rb', line 28
def self.configure(&block)
@@configure = block if block
end
|
.instance ⇒ Object
20
21
22
|
# File 'lib/circuitbox.rb', line 20
def self.instance
@@instance ||= new
end
|
.parameter_to_service_name(param) ⇒ Object
70
71
72
73
|
# File 'lib/circuitbox.rb', line 70
def self.parameter_to_service_name(param)
uri = URI(param.to_s)
uri.host.present? ? uri.host : param.to_s
end
|
.reset ⇒ Object
32
33
34
35
|
# File 'lib/circuitbox.rb', line 32
def self.reset
@@instance = nil
@@configure = nil
end
|
.stat_store ⇒ Object
45
46
47
|
# File 'lib/circuitbox.rb', line 45
def self.stat_store
self.instance.stat_store
end
|
.stat_store=(store) ⇒ Object
49
50
51
|
# File 'lib/circuitbox.rb', line 49
def self.stat_store=(store)
self.instance.stat_store = store
end
|