Module: Semian::CircuitBreakerBehaviour

Included in:
AdaptiveCircuitBreaker, CircuitBreaker, DualCircuitBreaker
Defined in:
lib/semian/circuit_breaker_behaviour.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exceptionsObject

Returns the value of attribute exceptions.



6
7
8
# File 'lib/semian/circuit_breaker_behaviour.rb', line 6

def exceptions
  @exceptions
end

#last_errorObject (readonly)

Returns the value of attribute last_error.



5
6
7
# File 'lib/semian/circuit_breaker_behaviour.rb', line 5

def last_error
  @last_error
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/semian/circuit_breaker_behaviour.rb', line 5

def name
  @name
end

Instance Method Details

#acquire(resource = nil, scope: nil, adapter: nil, &block) ⇒ Object

Main method to execute a block with circuit breaker protection

Raises:



15
16
17
# File 'lib/semian/circuit_breaker_behaviour.rb', line 15

def acquire(resource = nil, scope: nil, adapter: nil, &block)
  raise NotImplementedError, "#{self.class} must implement #acquire"
end

#closed?Boolean

Check if the circuit is closed (allowing requests)

Returns:

Raises:



35
36
37
# File 'lib/semian/circuit_breaker_behaviour.rb', line 35

def closed?
  raise NotImplementedError, "#{self.class} must implement #closed?"
end

#destroyObject

Clean up resources

Raises:



25
26
27
# File 'lib/semian/circuit_breaker_behaviour.rb', line 25

def destroy
  raise NotImplementedError, "#{self.class} must implement #destroy"
end

#half_open?Boolean

Check if the circuit is half-open (testing if service recovered)

Returns:

Raises:



40
41
42
# File 'lib/semian/circuit_breaker_behaviour.rb', line 40

def half_open?
  raise NotImplementedError, "#{self.class} must implement #half_open?"
end

#in_use?Boolean

Check if the circuit breaker is actively tracking failures

Returns:

Raises:



60
61
62
# File 'lib/semian/circuit_breaker_behaviour.rb', line 60

def in_use?
  raise NotImplementedError, "#{self.class} must implement #in_use?"
end

#initialize_behaviour(name:) ⇒ Object

Initialize common circuit breaker attributes



9
10
11
12
# File 'lib/semian/circuit_breaker_behaviour.rb', line 9

def initialize_behaviour(name:)
  @name = name.to_sym
  @last_error = nil
end

#mark_failed(error, scope: nil, adapter: nil) ⇒ Object

Mark a request as failed

Raises:



50
51
52
# File 'lib/semian/circuit_breaker_behaviour.rb', line 50

def mark_failed(error, scope: nil, adapter: nil)
  raise NotImplementedError, "#{self.class} must implement #mark_failed"
end

#mark_success(scope: nil, adapter: nil) ⇒ Object

Mark a request as successful

Raises:



55
56
57
# File 'lib/semian/circuit_breaker_behaviour.rb', line 55

def mark_success(scope: nil, adapter: nil)
  raise NotImplementedError, "#{self.class} must implement #mark_success"
end

#open?Boolean

Check if the circuit is open (rejecting requests)

Returns:

Raises:



30
31
32
# File 'lib/semian/circuit_breaker_behaviour.rb', line 30

def open?
  raise NotImplementedError, "#{self.class} must implement #open?"
end

#request_allowed?Boolean

Check if requests are currently allowed

Returns:

Raises:



45
46
47
# File 'lib/semian/circuit_breaker_behaviour.rb', line 45

def request_allowed?
  raise NotImplementedError, "#{self.class} must implement #request_allowed?"
end

#reset(scope: nil, adapter: nil) ⇒ Object

Reset the circuit breaker to its initial state

Raises:



20
21
22
# File 'lib/semian/circuit_breaker_behaviour.rb', line 20

def reset(scope: nil, adapter: nil)
  raise NotImplementedError, "#{self.class} must implement #reset"
end