class SwitchGear::CircuitBreaker::Failure

Attributes

error[R]
recorded[R]

Public Class Methods

from_json(json) click to toggle source
# File lib/switch_gear/circuit_breaker/failure.rb, line 5
def self.from_json(json)
  failure = JSON.parse(json)
  error = Object.const_get(failure["error"])
  error = error.new(failure["message"])
  new(error, Time.at(failure["timestamp"]).utc)
end
new(error, recorded = Time.now.utc) click to toggle source
# File lib/switch_gear/circuit_breaker/failure.rb, line 12
def initialize(error, recorded = Time.now.utc)
  @error = error
  @recorded = recorded
end

Public Instance Methods

timestamp() click to toggle source
# File lib/switch_gear/circuit_breaker/failure.rb, line 17
def timestamp
  recorded
end
to_json() click to toggle source
# File lib/switch_gear/circuit_breaker/failure.rb, line 25
def to_json
  JSON.generate({
    error: error.class,
    message: error.message,
    timestamp: timestamp.to_i
  })
end
to_s() click to toggle source
# File lib/switch_gear/circuit_breaker/failure.rb, line 21
def to_s
  "[#{error.class}] - #{error.message}"
end