Class: CircuitB::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/circuit_b/configuration.rb

Constant Summary collapse

DEFAULT_CONFIG =
{
  :log              => true,
  :timeout          => 5, # seconds
  :allowed_failures => 5,
  :cool_off_period  => 10 # seconds
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



18
19
20
21
22
# File 'lib/circuit_b/configuration.rb', line 18

def initialize
  @state_storage = CircuitB::Storage::Memory.new
  @default_fuse_config = DEFAULT_CONFIG.clone
  @fuses = {}
end

Instance Attribute Details

#default_fuse_configObject

Returns the value of attribute default_fuse_config.



15
16
17
# File 'lib/circuit_b/configuration.rb', line 15

def default_fuse_config
  @default_fuse_config
end

#fusesObject (readonly)

Returns the value of attribute fuses.



16
17
18
# File 'lib/circuit_b/configuration.rb', line 16

def fuses
  @fuses
end

#state_storageObject

Returns the value of attribute state_storage.



14
15
16
# File 'lib/circuit_b/configuration.rb', line 14

def state_storage
  @state_storage
end

Instance Method Details

#fuse(name, config = {}) ⇒ Object

Adds a fuse with a given name and custom config. If the fuse with the same name is already there, the RuntimeError is raised. The values of the provided configuration are used to override the default configuration that can be set with #default_fuse_config.

CircuitB.configure do |c|
  c.fuse "directory-auth", :on_break => lambda { notify_hoptoad(...) }, :allowed_failures => 5
  c.fuse "image-resizing", :allowed_failures => 2, :cool_off_period => 30
end


48
49
50
51
52
53
# File 'lib/circuit_b/configuration.rb', line 48

def fuse(name, config = {})
  raise "Fuse with this name is already registered" if @fuses.include?(name)

  config = @default_fuse_config.merge(config || {})
  @fuses[name] = CircuitB::Fuse.new(name, state_storage, config)
end