Class: Blazer::Check

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

Instance Method Summary collapse

Instance Method Details

#split_emailsObject



7
8
9
# File 'app/models/blazer/check.rb', line 7

def split_emails
  emails.to_s.downcase.split(",").map(&:strip)
end

#update_state(rows, error) ⇒ Object



11
12
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
# File 'app/models/blazer/check.rb', line 11

def update_state(rows, error)
  invert = respond_to?(:invert) && self.invert
  self.state =
    if error
      if error == Blazer::TIMEOUT_MESSAGE
        "timed out"
      else
        "error"
      end
    elsif rows.any?
      invert ? "passing" : "failing"
    else
      invert ? "failing" : "passing"
    end

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

  if respond_to?(:timeouts=)
    if state == "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 || state != "passing") && state != state_was && emails.present?
    Blazer::CheckMailer.state_change(self, state, state_was, rows.size, error).deliver_later
  end
  save! if changed?
end