Module: SwitchGear::CircuitBreaker

Included in:
Memory, Redis
Defined in:
lib/switch_gear/circuit_breaker.rb,
lib/switch_gear/circuit_breaker/redis.rb,
lib/switch_gear/circuit_breaker/memory.rb,
lib/switch_gear/circuit_breaker/failure.rb,
lib/switch_gear/circuit_breaker/open_error.rb

Defined Under Namespace

Classes: Failure, Memory, OpenError, Redis

Instance Method Summary collapse

Instance Method Details

#add_failure(failure) ⇒ void

This method returns an undefined value.

Parameters:



52
53
54
# File 'lib/switch_gear/circuit_breaker.rb', line 52

def add_failure(failure)
  must_implement(:add_failure)
end

#call(*args) ⇒ Void, SwitchGear::CircuitBreaker::Open

Calls the circuit proc/lambda if the circuit is closed or half-open.

Parameters:

  • args (Array<Object>)

    Any number of Objects to be called with the circuit block.

Returns:

  • (Void, SwitchGear::CircuitBreaker::Open)

    No usable return value if successful, but will raise an error if failure_limit is reached or if the circuit is open

Raises:



13
14
15
16
17
# File 'lib/switch_gear/circuit_breaker.rb', line 13

def call(*args)
  check_reset_timeout
  raise OpenError if open?
  do_run(args, &circuit)
end

#closed?Boolean

Returns Whether the circuit is closed

Returns:

  • (Boolean)

    Whether the circuit is closed



30
31
32
# File 'lib/switch_gear/circuit_breaker.rb', line 30

def closed?
  state == :closed
end

#failure_countInteger

Returns The count of current failures

Returns:

  • (Integer)

    The count of current failures



20
21
22
# File 'lib/switch_gear/circuit_breaker.rb', line 20

def failure_count
  failures.size
end

#failuresArray<SwitchGear::CircuitBreaker::Failure>

Returns a list of current failures

Returns:



40
41
42
# File 'lib/switch_gear/circuit_breaker.rb', line 40

def failures
  must_implement(:failures)
end

#failures=(failure) ⇒ void

This method returns an undefined value.

Parameters:



46
47
48
# File 'lib/switch_gear/circuit_breaker.rb', line 46

def failures=(failure)
  must_implement(:failures=)
end

#half_open?Boolean

Returns Whether the circuit is half-open

Returns:

  • (Boolean)

    Whether the circuit is half-open



35
36
37
# File 'lib/switch_gear/circuit_breaker.rb', line 35

def half_open?
  state == :half_open
end

#open?Boolean

Returns Whether the circuit is open

Returns:

  • (Boolean)

    Whether the circuit is open



25
26
27
# File 'lib/switch_gear/circuit_breaker.rb', line 25

def open?
  state == :open
end

#stateSymbol

Returns - either :open, :closed, :half-open

Returns:

  • (Symbol)
    • either :open, :closed, :half-open



57
58
59
# File 'lib/switch_gear/circuit_breaker.rb', line 57

def state
  must_implement(:state)
end

#state=(state) ⇒ void

This method returns an undefined value.

Parameters:

  • state (Symbol)
    • either :open, :closed, :half-open



63
64
65
# File 'lib/switch_gear/circuit_breaker.rb', line 63

def state=(state)
  must_implement(:state=)
end