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) ⇒ Diagnostic
constructor
A new instance of Diagnostic.
- #pass(message = {}, data = {}) ⇒ Object
- #run ⇒ Object
- #should_run? ⇒ Boolean
Constructor Details
#initialize(config, options) ⇒ Diagnostic
Returns a new instance of Diagnostic.
13 14 15 16 17 18 |
# File 'lib/hive/diagnostic.rb', line 13 def initialize(config, ) @options = @config = config @serial = @options['serial'] @device_api = @options['device_api'] 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
49 50 51 52 |
# File 'lib/hive/diagnostic.rb', line 49 def fail( ={}, data = {}) Hive.logger.info() Hive::Results.new("fail", , data) end |
#pass(message = {}, data = {}) ⇒ Object
44 45 46 47 |
# File 'lib/hive/diagnostic.rb', line 44 def pass(= {}, data = {}) Hive.logger.info() Hive::Results.new("pass", , data ) end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hive/diagnostic.rb', line 32 def run Hive.logger.info("Trying to run diagnostic '#{self.class}'") if should_run? result = diagnose result = repair(result) if result.failed? @last_run = result else Hive.logger.info("Diagnostic '#{self.class}' last ran less than five minutes before") end @last_run end |
#should_run? ⇒ Boolean
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hive/diagnostic.rb', line 20 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 |