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
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
|