Class: AppStatus::CheckItem

Inherits:
Object
  • Object
show all
Defined in:
app/models/app_status/check_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CheckItem

Returns a new instance of CheckItem.



8
9
10
11
12
13
14
# File 'app/models/app_status/check_item.rb', line 8

def initialize(name)
  @name = name
  @proc = nil
  @description = ''

  reset
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'app/models/app_status/check_item.rb', line 6

def description
  @description
end

#detailsObject (readonly)

Returns the value of attribute details.



5
6
7
# File 'app/models/app_status/check_item.rb', line 5

def details
  @details
end

#msObject (readonly)

Returns the value of attribute ms.



5
6
7
# File 'app/models/app_status/check_item.rb', line 5

def ms
  @ms
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'app/models/app_status/check_item.rb', line 5

def name
  @name
end

#procObject

Returns the value of attribute proc.



6
7
8
# File 'app/models/app_status/check_item.rb', line 6

def proc
  @proc
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'app/models/app_status/check_item.rb', line 5

def status
  @status
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



5
6
7
# File 'app/models/app_status/check_item.rb', line 5

def status_code
  @status_code
end

Instance Method Details

#as_hashObject



45
46
47
48
49
50
51
52
# File 'app/models/app_status/check_item.rb', line 45

def as_hash
  {
    status: @status,
    status_code: @status_code,
    details: @details,
    ms: @ms
  }
end

#evaluate!Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/app_status/check_item.rb', line 24

def evaluate!
  check_start = Time.now
  status, details = @proc ? @proc.call : [:unknown, "Check is not configured."]
  check_time = (Time.now - check_start) * 1000

  status = status.to_sym if status
  details = details.to_s if details

  if ! valid_status?(status)
    details = "Check returned invalid status '#{status}'. #{details}".strip
    status = :unknown
  end

  @status = status
  @status_code = CheckCollection.valid_status_map[@status]
  @details = details
  @ms = check_time.to_i

  return @status_code
end

#html_descriptionObject



54
55
56
# File 'app/models/app_status/check_item.rb', line 54

def html_description
  Kramdown::Document.new(@description).to_html
end

#resetObject



16
17
18
# File 'app/models/app_status/check_item.rb', line 16

def reset
  @result = {}
end

#valid_status?(status) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'app/models/app_status/check_item.rb', line 20

def valid_status?(status)
  CheckCollection.valid_status_map.keys.include?(status)
end