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.
20 21 22 23 24 25 |
# File 'lib/semian/protected_resource.rb', line 20 def initialize(name, bulkhead, circuit_breaker) @name = name @bulkhead = bulkhead @circuit_breaker = circuit_breaker @updated_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) end |
Instance Attribute Details
#bulkhead ⇒ Object (readonly)
Returns the value of attribute bulkhead.
17 18 19 |
# File 'lib/semian/protected_resource.rb', line 17 def bulkhead @bulkhead end |
#circuit_breaker ⇒ Object (readonly)
Returns the value of attribute circuit_breaker.
17 18 19 |
# File 'lib/semian/protected_resource.rb', line 17 def circuit_breaker @circuit_breaker end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/semian/protected_resource.rb', line 17 def name @name end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
18 19 20 |
# File 'lib/semian/protected_resource.rb', line 18 def updated_at @updated_at end |
Instance Method Details
#acquire(timeout: nil, scope: nil, adapter: nil, resource: nil) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/semian/protected_resource.rb', line 32 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
27 28 29 30 |
# File 'lib/semian/protected_resource.rb', line 27 def destroy @bulkhead&.destroy @circuit_breaker&.destroy end |
#in_use? ⇒ Boolean
41 42 43 |
# File 'lib/semian/protected_resource.rb', line 41 def in_use? circuit_breaker&.in_use? || bulkhead&.in_use? end |