Business intelligence made simple
Added timed out and disabled states for checks
Andrew Kane3befc3a7727a
diff --git a/app/controllers/blazer/checks_controller.rb b/app/controllers/blazer/checks_controller.rbindex 912064b0..7d9f257c 100644--- a/app/controllers/blazer/checks_controller.rb+++ b/app/controllers/blazer/checks_controller.rb@@ -3,7 +3,8 @@ module Blazerbefore_action :set_check, only: [:edit, :update, :destroy, :run]def index- @checks = Blazer::Check.joins(:query).includes(:query).order("state, blazer_queries.name, blazer_checks.id").to_a+ state_order = [nil, "disabled", "error", "timed out", "failing", "passing"]+ @checks = Blazer::Check.joins(:query).includes(:query).order("blazer_queries.name, blazer_checks.id").to_a.sort_by { |q| state_order.index(q.state) || 99 }@checks.select! { |c| "#{c.query.name} #{c.emails}".downcase.include?(params[:q]) } if params[:q]enddiff --git a/app/models/blazer/check.rb b/app/models/blazer/check.rbindex 2976ab90..07c0f40c 100644--- a/app/models/blazer/check.rb+++ b/app/models/blazer/check.rb@@ -5,21 +5,34 @@ module Blazervalidates :query_id, presence: truedef split_emails- emails.to_s.split(",").map(&:strip)+ emails.to_s.downcase.split(",").map(&:strip)enddef update_state(rows, error)- invert = self.respond_to?(:invert) && self.invert+ invert = respond_to?(:invert) && self.invertself.state =if error- "error"+ if error == Blazer::TIMEOUT_MESSAGE+ "timed out"+ else+ "error"+ endelsif rows.any?invert ? "passing" : "failing"elseinvert ? "failing" : "passing"end- self.last_run_at = Time.now if self.respond_to?(:last_run_at=)+ 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 passingif (state_was || state != "passing") && state != state_was && emails.present?diff --git a/app/views/blazer/checks/index.html.erb b/app/views/blazer/checks/index.html.erbindex d8809898..a1701e36 100644--- a/app/views/blazer/checks/index.html.erb+++ b/app/views/blazer/checks/index.html.erb@@ -3,7 +3,7 @@<p style="float: right;"><%= link_to "New Check", new_check_path, class: "btn btn-info" %></p><%= render partial: "blazer/nav" %>-<% colors = {failing: "red", passing: "#5cb85c", error: "#666"} %>+<% colors = {failing: "red", passing: "#5cb85c", error: "#666", timed_out: "orange", disabled: "#000"} %><table class="table"><thead><tr>@@ -20,7 +20,7 @@<td><%= link_to check.query.name, check.query %></td><td><% if check.state %>- <small style="font-weight: bold; color: <%= colors[check.state.to_sym] %>;"><%= check.state.upcase %></small>+ <small style="font-weight: bold; color: <%= colors[check.state.parameterize("_").to_sym] %>;"><%= check.state.upcase %></small><% end %></td><td><%= check.schedule if check.respond_to?(:schedule) %></td>diff --git a/lib/blazer.rb b/lib/blazer.rbindex b4da5dc4..bbe035c5 100644--- a/lib/blazer.rb+++ b/lib/blazer.rb@@ -106,7 +106,7 @@ module Blazerdef self.send_failing_checksemails = {}- Blazer::Check.includes(:query).where(state: %w[failing error]).find_each do |check|+ Blazer::Check.includes(:query).where(state: ["failing", "error", "timed out", "disabled"]).find_each do |check|check.split_emails.each do |email|(emails[email] ||= []) << checkenddiff --git a/lib/generators/blazer/templates/install.rb b/lib/generators/blazer/templates/install.rbindex 01fadbc0..235b6244 100644--- a/lib/generators/blazer/templates/install.rb+++ b/lib/generators/blazer/templates/install.rb@@ -38,6 +38,7 @@ class <%= migration_class_name %> < ActiveRecord::Migrationt.text :emailst.boolean :invertt.timestamp :last_run_at+ t.integer :timeouts, default: 0t.timestampsendend