Class: Semian::ProtectedResource
- Inherits:
-
Object
- Object
- Semian::ProtectedResource
- Extended by:
- Forwardable
- Defined in:
- lib/semian/protected_resource.rb
Instance Attribute Summary collapse
-
#bulkhead ⇒ Object
readonly
Returns the value of attribute bulkhead.
-
#circuit_breaker ⇒ Object
readonly
Returns the value of attribute circuit_breaker.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #acquire(timeout: nil, scope: nil, adapter: nil, resource: nil) ⇒ Object
- #destroy ⇒ Object
- #in_use? ⇒ Boolean
-
#initialize(name, bulkhead, circuit_breaker) ⇒ ProtectedResource
constructor
A new instance of ProtectedResource.
Constructor Details
#initialize(name, bulkhead, circuit_breaker) ⇒ ProtectedResource
Returns a new instance of ProtectedResource.
12 13 14 15 16 17 |
# File 'lib/semian/protected_resource.rb', line 12 def initialize(name, bulkhead, circuit_breaker) @name = name @bulkhead = bulkhead @circuit_breaker = circuit_breaker @updated_at = Time.now end |
Instance Attribute Details
#bulkhead ⇒ Object (readonly)
Returns the value of attribute bulkhead.
9 10 11 |
# File 'lib/semian/protected_resource.rb', line 9 def bulkhead @bulkhead end |
#circuit_breaker ⇒ Object (readonly)
Returns the value of attribute circuit_breaker.
9 10 11 |
# File 'lib/semian/protected_resource.rb', line 9 def circuit_breaker @circuit_breaker end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/semian/protected_resource.rb', line 9 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
10 11 12 |
# File 'lib/semian/protected_resource.rb', line 10 def updated_at @updated_at end |
Instance Method Details
#acquire(timeout: nil, scope: nil, adapter: nil, resource: nil) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/semian/protected_resource.rb', line 24 def acquire(timeout: nil, scope: nil, adapter: nil, resource: nil) acquire_circuit_breaker(scope, adapter, resource) do acquire_bulkhead(timeout, scope, adapter) do |_, wait_time| Semian.notify(:success, self, scope, adapter, wait_time) yield self end end end |
#destroy ⇒ Object
19 20 21 22 |
# File 'lib/semian/protected_resource.rb', line 19 def destroy @bulkhead.destroy unless @bulkhead.nil? @circuit_breaker.destroy unless @circuit_breaker.nil? end |
#in_use? ⇒ Boolean
33 34 35 |
# File 'lib/semian/protected_resource.rb', line 33 def in_use? circuit_breaker&.in_use? || bulkhead&.in_use? end |