Class: Blazer::Check

Inherits:
Record
  • Object
show all
Defined in:
app/models/blazer/check.rb

Instance Method Summary collapse

Instance Method Details

#computed_check_typeObject



46
47
48
49
50
51
52
53
54
# File 'app/models/blazer/check.rb', line 46

def computed_check_type
  if respond_to?(:check_type)
    check_type
  elsif respond_to?(:invert)
    invert ? "missing_data" : "bad_data"
  else
    "bad_data"
  end
end

#update_state(result) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/blazer/check.rb', line 13

def update_state(result)
  check_type = computed_check_type

  self.state, message =
    if result.timed_out?
      ["timed out", result.error]
    elsif result.error
      ["error", result.error]
    else
      Blazer.check_types.fetch(check_type).fetch(:block).call(result)
    end

  self.last_run_at = Time.now if respond_to?(:last_run_at=)
  self.message = message if respond_to?(:message=)

  if respond_to?(:timeouts=)
    if result.timed_out?
      self.timeouts += 1
      self.state = "disabled" if timeouts >= 3
    else
      self.timeouts = 0
    end
  end

  # do not notify on creation, except when not passing
  if (state_was != "new" || state != "passing") && state != state_was
    Blazer.notifiers.each do |notifier|
      notifier.state_change(check: self, state:, state_was:, result:, message:, check_type:)
    end
  end
  save! if changed?
end