mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-06 02:35:11 +02:00
Display an icon for check in error
This commit is contained in:
parent
9279d8eed4
commit
3bfca3b81f
|
@ -13,8 +13,13 @@ import Turbolinks from 'turbolinks';
|
|||
import 'bootstrap/js/dist/collapse';
|
||||
import 'bootstrap/js/dist/dropdown';
|
||||
import 'bootstrap/js/dist/button';
|
||||
import 'bootstrap/js/dist/tooltip';
|
||||
|
||||
import '../scss';
|
||||
|
||||
Rails.start()
|
||||
Turbolinks.start()
|
||||
|
||||
document.addEventListener("turbolinks:load", () => {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
});
|
||||
|
|
|
@ -2,4 +2,8 @@
|
|||
.action a {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.kind .octicon {
|
||||
vertical-align: middle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,4 +49,10 @@ module ChecksHelper
|
|||
"btn-outline-info"
|
||||
end
|
||||
end
|
||||
|
||||
def check_last_success_title(check)
|
||||
return t(".never_succeeded") if check.last_success_at.nil?
|
||||
|
||||
t(".days_from_last_success", count: check.days_from_last_success)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#
|
||||
|
||||
class Check < ApplicationRecord
|
||||
ERROR_DELAY_DAYS = 3
|
||||
|
||||
belongs_to :user
|
||||
has_many :logs, class_name: "CheckLog"
|
||||
has_many :notifications, validate: true, dependent: :destroy
|
||||
|
@ -61,14 +63,29 @@ class Check < ApplicationRecord
|
|||
scope :kind, ->(kind) { where(kind: kind) }
|
||||
scope :by_domain, ->(domain) { where("domain LIKE ?", "%#{domain}%") }
|
||||
scope :recurrent_failures, -> {
|
||||
where("last_run_at IS NOT NULL")
|
||||
.where("last_success_at IS NULL OR last_success_at <= DATE_SUB(last_run_at, INTERVAL 3 DAY)")
|
||||
interval = "INTERVAL #{ERROR_DELAY_DAYS} DAY"
|
||||
where("last_run_at IS NOT NULL AND created_at <= DATE_SUB(NOW(), #{interval})")
|
||||
.where("last_success_at IS NULL OR last_success_at <= DATE_SUB(last_run_at, #{interval})")
|
||||
}
|
||||
|
||||
def self.default_sort
|
||||
{ domain_expires_at: :asc }
|
||||
end
|
||||
|
||||
def in_error?
|
||||
return false if created_at > ERROR_DELAY_DAYS.days.ago
|
||||
return false if last_run_at.nil?
|
||||
return true if last_success_at.nil?
|
||||
|
||||
last_success_at < ERROR_DELAY_DAYS.days.ago
|
||||
end
|
||||
|
||||
def days_from_last_success
|
||||
return unless last_success_at.present?
|
||||
|
||||
(Date.today - last_success_at.to_date).to_i
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def domain_created_at_past
|
||||
|
|
|
@ -21,8 +21,19 @@
|
|||
<tbody>
|
||||
<% checks.each do |check| %>
|
||||
<tr class="check-row <%= check_row_class(check) %>">
|
||||
<td>
|
||||
<td class="kind">
|
||||
<span class="badge badge-info"><%= t(".kind_labels.#{check.kind}") %></span>
|
||||
<%- if check.in_error? %>
|
||||
<%== content_tag(
|
||||
:span,
|
||||
Octicons::Octicon.new("alert", class: "ml-1").to_svg.html_safe,
|
||||
class: "text-danger",
|
||||
data: {
|
||||
toggle: "tooltip",
|
||||
placement: "right",
|
||||
title: check_last_success_title(check)
|
||||
}) %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<strong><%= check.domain %></strong>
|
||||
|
|
|
@ -109,3 +109,8 @@ en:
|
|||
kind_labels:
|
||||
domain: Domain
|
||||
ssl: SSL
|
||||
never_succeeded: "Chexpire has never been able to perform a check."
|
||||
days_from_last_success:
|
||||
zero: "Last check successful: today"
|
||||
one: "Last check successful: yesterday"
|
||||
other: "Last check successful %{count} days ago"
|
||||
|
|
|
@ -144,3 +144,8 @@ fr:
|
|||
kind_labels:
|
||||
domain: Domaine
|
||||
ssl: SSL
|
||||
never_succeeded: "Chexpire n'a jamais pu effectuer de vérification."
|
||||
days_from_last_success:
|
||||
zero: "Dernière vérification réussie : aujourd'hui"
|
||||
one: "Dernière vérification réussie : hier"
|
||||
other: "Dernière vérification réussie il y a %{count} jours"
|
||||
|
|
23
db/seeds.rb
23
db/seeds.rb
|
@ -19,6 +19,8 @@ user2 = User.create!(
|
|||
locale: :en,
|
||||
)
|
||||
|
||||
users = [user1, user2]
|
||||
|
||||
check_chexpire_org = Check.create!(
|
||||
user: user1,
|
||||
kind: :domain,
|
||||
|
@ -40,7 +42,7 @@ check_chexpire_org_error = Check.create!(
|
|||
comment: "The date are fake, this is a seed !",
|
||||
vendor: "Some random registrar",
|
||||
last_run_at: 20.minutes.ago,
|
||||
last_success_at: 4.days.ago,
|
||||
created_at: 3.weeks.ago,
|
||||
)
|
||||
|
||||
ssl_check_chexpire_org = Check.create!(
|
||||
|
@ -68,12 +70,12 @@ ssl_check_chexpire_org_error = Check.create!(
|
|||
)
|
||||
|
||||
|
||||
100.times do |i|
|
||||
def check_factory(users)
|
||||
ext = %w[com net org fr].sample
|
||||
word = (0...rand(4..12)).map { (97 + rand(26)).chr }.join
|
||||
|
||||
Check.create!(
|
||||
user: [user1, user2].sample,
|
||||
Check.new(
|
||||
user: users.sample,
|
||||
kind: Check.kinds.keys.sample,
|
||||
domain: "#{word}.#{ext}",
|
||||
domain_expires_at: rand(8..300).days.from_now,
|
||||
|
@ -82,6 +84,19 @@ ssl_check_chexpire_org_error = Check.create!(
|
|||
)
|
||||
end
|
||||
|
||||
100.times do |i|
|
||||
check_factory(users).save!
|
||||
end
|
||||
|
||||
# checks with error
|
||||
10.times do |i|
|
||||
check_factory(users).update_attributes(
|
||||
created_at: rand(1..300).days.ago,
|
||||
last_run_at: 4.hours.ago,
|
||||
last_success_at: rand(10...100).days.ago,
|
||||
)
|
||||
end
|
||||
|
||||
Notification.create!(
|
||||
check: check_chexpire_org,
|
||||
interval: 15,
|
||||
|
|
|
@ -117,7 +117,7 @@ class ChecksControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "checks in error are filtered" do
|
||||
c1 = create(:check, :last_runs_failed, user: @user)
|
||||
c1 = create(:check, :last_runs_failed, created_at: 1.week.ago, user: @user)
|
||||
create(:check, user: @user)
|
||||
|
||||
get checks_path(recurrent_failures: true)
|
||||
|
|
|
@ -49,4 +49,56 @@ class CheckTest < ActiveSupport::TestCase
|
|||
assert notification.pending?
|
||||
assert_nil notification.sent_at
|
||||
end
|
||||
|
||||
test "in_error? for recently added" do
|
||||
check = build(:check, created_at: 1.day.ago)
|
||||
refute check.in_error?
|
||||
|
||||
check = build(:check, created_at: 1.day.ago, last_run_at: 3.minutes.ago)
|
||||
refute check.in_error?
|
||||
|
||||
check = build(:check, created_at: 1.day.ago, last_success_at: 1.hour.ago)
|
||||
refute check.in_error?
|
||||
end
|
||||
|
||||
test "in_error? for never success check, with at least 1 run" do
|
||||
check = build(:check, created_at: 3.weeks.ago, last_run_at: 1.day.ago)
|
||||
assert check.in_error?
|
||||
|
||||
check = build(:check, created_at: 3.weeks.ago, last_run_at: 4.days.ago)
|
||||
assert check.in_error?
|
||||
end
|
||||
|
||||
test "in_error? ignore check without run" do
|
||||
check = build(:check, created_at: 3.weeks.ago)
|
||||
refute check.in_error?
|
||||
end
|
||||
|
||||
test "in_error? for last success a few days ago" do
|
||||
check = build(:check, created_at: 3.weeks.ago,
|
||||
last_success_at: 10.days.ago, last_run_at: 1.day.ago)
|
||||
assert check.in_error?
|
||||
|
||||
check = build(:check, created_at: 3.weeks.ago,
|
||||
last_success_at: 1.days.ago, last_run_at: 1.day.ago)
|
||||
refute check.in_error?
|
||||
end
|
||||
|
||||
test "days_from_last_success without any success" do
|
||||
check = build(:check)
|
||||
assert_nil check.days_from_last_success
|
||||
|
||||
check = build(:check, last_run_at: 1.day.ago)
|
||||
assert_nil check.days_from_last_success
|
||||
end
|
||||
|
||||
test "days_from_last_success" do
|
||||
check = build(:check, last_success_at: 10.days.ago - 1.hour)
|
||||
assert_equal 10, check.days_from_last_success
|
||||
end
|
||||
|
||||
test "days_from_last_success with a time" do
|
||||
check = build(:check, last_success_at: (10.1 * 24).hours.ago)
|
||||
assert_equal 10, check.days_from_last_success
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue