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/async_support.rb,
lib/breaker_machines/storage/cache.rb,
lib/breaker_machines/storage/memory.rb,
lib/breaker_machines/hedged_execution.rb,
lib/breaker_machines/circuit/callbacks.rb,
lib/breaker_machines/circuit/execution.rb,
lib/breaker_machines/hedged_async_support.rb,
lib/breaker_machines/circuit/configuration.rb,
lib/breaker_machines/circuit/introspection.rb,
lib/breaker_machines/storage/bucket_memory.rb,
lib/breaker_machines/storage/fallback_chain.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: AsyncSupport, DSL, HedgedAsyncSupport, HedgedExecution, Storage Classes: Circuit, CircuitBulkheadError, CircuitOpenError, CircuitTimeoutError, ConfigurationError, Console, Error, Registry, StorageError, StorageTimeoutError

Constant Summary collapse

VERSION =
'0.3.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



58
59
60
# File 'lib/breaker_machines.rb', line 58

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

Class Method Details

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

Yields:

  • (config)


36
37
38
# File 'lib/breaker_machines.rb', line 36

def configure
  yield config
end

.consoleObject

Launch the interactive console



71
72
73
74
# File 'lib/breaker_machines.rb', line 71

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

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



64
65
66
67
68
# File 'lib/breaker_machines.rb', line 64

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

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

.loaderObject



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

def loader
  loader
end

.registryObject

Get the global registry



77
78
79
# File 'lib/breaker_machines.rb', line 77

def registry
  Registry.instance
end

.setup_notificationsObject



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

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