Skip to content

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.rb
index 912064b0..7d9f257c 100644
--- a/app/controllers/blazer/checks_controller.rb
+++ b/app/controllers/blazer/checks_controller.rb
@@ -3,7 +3,8 @@ module Blazer
before_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]
end
diff --git a/app/models/blazer/check.rb b/app/models/blazer/check.rb
index 2976ab90..07c0f40c 100644
--- a/app/models/blazer/check.rb
+++ b/app/models/blazer/check.rb
@@ -5,21 +5,34 @@ module Blazer
validates :query_id, presence: true
def split_emails
- emails.to_s.split(",").map(&:strip)
+ emails.to_s.downcase.split(",").map(&:strip)
end
def update_state(rows, error)
- invert = self.respond_to?(:invert) && self.invert
+ invert = respond_to?(:invert) && self.invert
self.state =
if error
- "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 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 passing
if (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.erb
index 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.rb
index b4da5dc4..bbe035c5 100644
--- a/lib/blazer.rb
+++ b/lib/blazer.rb
@@ -106,7 +106,7 @@ module Blazer
def self.send_failing_checks
emails = {}
- 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] ||= []) << check
end
diff --git a/lib/generators/blazer/templates/install.rb b/lib/generators/blazer/templates/install.rb
index 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::Migration
t.text :emails
t.boolean :invert
t.timestamp :last_run_at
+ t.integer :timeouts, default: 0
t.timestamps
end
end