Module: BreakerMachines

Includes:
ActiveSupport::Configurable
Defined in:
lib/breaker_machines.rb,
lib/breaker_machines/dsl.rb,
lib/breaker_machines/errors.rb,
lib/breaker_machines/circuit.rb,
lib/breaker_machines/console.rb,
lib/breaker_machines/storage.rb,
lib/breaker_machines/version.rb,
lib/breaker_machines/registry.rb,
lib/breaker_machines/storage/base.rb,
lib/breaker_machines/storage/null.rb,
lib/breaker_machines/storage/memory.rb,
lib/breaker_machines/circuit/callbacks.rb,
lib/breaker_machines/circuit/execution.rb,
lib/breaker_machines/circuit/configuration.rb,
lib/breaker_machines/circuit/introspection.rb,
lib/breaker_machines/storage/bucket_memory.rb,
lib/breaker_machines/circuit/state_management.rb

Overview

BreakerMachines provides a thread-safe implementation of the Circuit Breaker pattern for Ruby applications, helping to prevent cascading failures in distributed systems.

Defined Under Namespace

Modules: DSL, Storage Classes: Circuit, CircuitOpenError, CircuitTimeoutError, ConfigurationError, Console, Error, Registry, StorageError

Constant Summary collapse

VERSION =
'0.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



56
57
58
# File 'lib/breaker_machines.rb', line 56

def logger
  @logger ||= ActiveSupport::Logger.new($stdout)
end

Class Method Details

.configure {|config| ... } ⇒ Object

Yields:

  • (config)


34
35
36
# File 'lib/breaker_machines.rb', line 34

def configure
  yield config
end

.consoleObject

Launch the interactive console



69
70
71
72
# File 'lib/breaker_machines.rb', line 69

def console
  require_relative 'breaker_machines/console'
  Console.start
end

.instrument(event, payload = {}) ⇒ Object



62
63
64
65
66
# File 'lib/breaker_machines.rb', line 62

def instrument(event, payload = {})
  return unless config.log_events

  ActiveSupport::Notifications.instrument("breaker_machines.#{event}", payload)
end

.loaderObject



18
19
20
# File 'lib/breaker_machines.rb', line 18

def loader
  loader
end

.registryObject

Get the global registry



75
76
77
# File 'lib/breaker_machines.rb', line 75

def registry
  Registry.instance
end

.setup_notificationsObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/breaker_machines.rb', line 38

def setup_notifications
  return unless config.log_events

  ActiveSupport::Notifications.subscribe(/^breaker_machines\./) do |name, _start, _finish, _id, payload|
    event_type = name.split('.').last
    circuit_name = payload[:circuit]

    case event_type
    when 'opened'
      logger&.warn "[BreakerMachines] Circuit '#{circuit_name}' opened"
    when 'closed'
      logger&.info "[BreakerMachines] Circuit '#{circuit_name}' closed"
    when 'half_opened'
      logger&.info "[BreakerMachines] Circuit '#{circuit_name}' half-opened"
    end
  end
end