Class: Philiprehberger::CircuitBoard::Configuration

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

Overview

DSL for defining health checks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
# File 'lib/philiprehberger/circuit_board/configuration.rb', line 9

def initialize
  @checks = []
  @on_change = nil
end

Instance Attribute Details

#checksObject (readonly)

Returns the value of attribute checks.



7
8
9
# File 'lib/philiprehberger/circuit_board/configuration.rb', line 7

def checks
  @checks
end

Instance Method Details

#check(name, timeout: 5, critical: true, cache: nil, &block) ⇒ void

This method returns an undefined value.

Register a health check.

Parameters:

  • name (Symbol)

    the check name

  • timeout (Numeric) (defaults to: 5)

    timeout in seconds

  • critical (Boolean) (defaults to: true)

    whether this check is critical (default: true)

  • cache (Numeric, nil) (defaults to: nil)

    cache successful results for this many seconds (default: nil — no caching)

  • block (Proc)

    block that returns truthy if healthy



22
23
24
# File 'lib/philiprehberger/circuit_board/configuration.rb', line 22

def check(name, timeout: 5, critical: true, cache: nil, &block)
  @checks << Check.new(name, timeout: timeout, critical: critical, cache: cache, &block)
end

#on_change {|Symbol, Symbol| ... } ⇒ void

This method returns an undefined value.

Register a callback for health status transitions.

Yields:

  • (Symbol, Symbol)

    previous status and new status



30
31
32
# File 'lib/philiprehberger/circuit_board/configuration.rb', line 30

def on_change(&block)
  @on_change = block
end

#on_change_callbackProc?

Returns the on_change callback.

Returns:

  • (Proc, nil)

    the on_change callback



35
36
37
# File 'lib/philiprehberger/circuit_board/configuration.rb', line 35

def on_change_callback
  @on_change
end