class Hive::Diagnostic
Attributes
config[R]
device_api[R]
last_run[RW]
Public Class Methods
new(config, options, hive_mind=nil)
click to toggle source
# File lib/hive/diagnostic.rb, line 13 def initialize(config, options, hive_mind=nil) @options = options @config = config @serial = @options['serial'] @device_api = @options['device_api'] @hive_mind = hive_mind end
Public Instance Methods
fail(message ={}, data = {})
click to toggle source
# File lib/hive/diagnostic.rb, line 50 def fail(message ={}, data = {}) Hive.logger.info("#{@device_api.serial} => #{message} #{data}") Hive::Results.new("fail", message, data, @hive_mind) end
pass(message= {}, data = {})
click to toggle source
# File lib/hive/diagnostic.rb, line 45 def pass(message= {}, data = {}) Hive.logger.info("#{@device_api.serial} => #{message} #{data}") Hive::Results.new("pass", message, data, @hive_mind) end
run()
click to toggle source
# File lib/hive/diagnostic.rb, line 33 def run Hive.logger.debug("Trying to run diagnostic '#{self.class}'") if should_run? result = diagnose result = repair(result) if result.failed? @last_run = result else Hive.logger.debug("Diagnostic '#{self.class}' last ran less than five minutes before") end @last_run end
should_run?()
click to toggle source
# File lib/hive/diagnostic.rb, line 21 def should_run? return true if @last_run == nil time_now = Time.new.getutc last_run_time = @last_run.timestamp diff = ((time_now - last_run_time)/300).round if (diff > 2 && @last_run.passed?) || diff > 1 true else false end end