Class: Hive::Diagnostic

Inherits:
Object
  • Object
show all
Defined in:
lib/hive/diagnostic.rb

Defined Under Namespace

Classes: InvalidParameterError

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options, hive_mind=nil)
  @options = options
  @config = config
  @serial = @options['serial']
  @device_api = @options['device_api']
  @hive_mind = hive_mind
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/hive/diagnostic.rb', line 11

def config
  @config
end

#device_apiObject (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_runObject

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(message ={}, data = {})
  Hive.logger.info("#{@device_api.serial_no} => #{message} #{data}")
  Hive::Results.new("fail", message, data, @hive_mind)
end

#pass(message = {}, data = {}) ⇒ Object



45
46
47
48
# File 'lib/hive/diagnostic.rb', line 45

def pass(message= {}, data = {})
  Hive.logger.info("#{@device_api.serial_no} => #{message} #{data}")
  Hive::Results.new("pass", message, data, @hive_mind)
end

#runObject



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

Returns:

  • (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.timestamp
  diff = ((time_now - last_run_time)/300).round
  if (diff > 2 && @last_run.passed?) || diff > 1
    true
  else
    false
  end
end