Class: Hive::Diagnostic
- Inherits:
-
Object
- Object
- Hive::Diagnostic
- Defined in:
- lib/hive/diagnostic.rb
Defined Under Namespace
Classes: InvalidParameterError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#device_api ⇒ Object
readonly
Returns the value of attribute device_api.
-
#last_run ⇒ Object
Returns the value of attribute last_run.
Instance Method Summary collapse
- #fail(message = {}, data = {}) ⇒ Object
-
#initialize(config, options, hive_mind = nil) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #pass(message = {}, data = {}) ⇒ Object
- #run ⇒ Object
- #should_run? ⇒ Boolean
Constructor Details
#initialize(config, options, hive_mind = nil) ⇒ Diagnostic
Returns a new instance of Diagnostic.
13 14 15 16 17 18 19 |
# File 'lib/hive/diagnostic.rb', line 13 def initialize(config, , hive_mind=nil) = @config = config @serial = ['serial'] @device_api = ['device_api'] @hive_mind = hive_mind end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
11 12 13 |
# File 'lib/hive/diagnostic.rb', line 11 def config @config end |
#device_api ⇒ Object (readonly)
Returns the value of attribute device_api.
11 12 13 |
# File 'lib/hive/diagnostic.rb', line 11 def device_api @device_api end |
#last_run ⇒ Object
Returns the value of attribute last_run.
10 11 12 |
# File 'lib/hive/diagnostic.rb', line 10 def last_run @last_run end |
Instance Method Details
#fail(message = {}, data = {}) ⇒ Object
50 51 52 53 |
# File 'lib/hive/diagnostic.rb', line 50 def fail( ={}, data = {}) Hive.logger.info("#{@device_api.serial_no} => #{message} #{data}") Hive::Results.new("fail", , data, @hive_mind) end |
#pass(message = {}, data = {}) ⇒ Object
45 46 47 48 |
# File 'lib/hive/diagnostic.rb', line 45 def pass(= {}, data = {}) Hive.logger.info("#{@device_api.serial_no} => #{message} #{data}") Hive::Results.new("pass", , data, @hive_mind) end |
#run ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# 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? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 |
# 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. diff = ((time_now - last_run_time)/300).round if (diff > 2 && @last_run.passed?) || diff > 1 true else false end end |