Class: StatusLib::StatusInfo
- Inherits:
-
Object
- Object
- StatusLib::StatusInfo
- Defined in:
- lib/status_lib/status_info.rb
Instance Method Summary collapse
-
#initialize(api) ⇒ StatusInfo
constructor
A new instance of StatusInfo.
- #switch(name, status, options = {}) ⇒ Object
- #up?(name) ⇒ Boolean
Constructor Details
#initialize(api) ⇒ StatusInfo
Returns a new instance of StatusInfo.
2 3 4 5 6 7 |
# File 'lib/status_lib/status_info.rb', line 2 def initialize(api) @api = api @statuses = {} @expiries = {} @updates = {} end |
Instance Method Details
#switch(name, status, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/status_lib/status_info.rb', line 21 def switch(name, status, ={}) unless [:up, :down].include?(status) raise ArgumentError.new("unknown status") end expires = .fetch(:for, StatusLib.config.down_duration) expires = now + expires unless expires.nil? @statuses[name] = status @expiries[name] = expires add_pending_update(name, status, expires) send_pending_updates StatusLib.config.stats_handler.increment("status.change.#{name}.#{status}") end |
#up?(name) ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/status_lib/status_info.rb', line 9 def up?(name) sync_status_list status = @statuses[name] expiry = @expiries[name] if status == :down && (expiry.nil? || expiry > now) return false else return true end end |