Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Discard Cleaner" page to dashboard UI #1538

Merged
merged 6 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions app/controllers/good_job/cleaner_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

module GoodJob
class CleanerController < ApplicationController
def index
@filter = JobsFilter.new(params)

@discarded_jobs_grouped_by_exception =
GoodJob::Job.discarded
.select(<<-SQL.squish)
SPLIT_PART(error, ': ', 1) AS exception_class,
count(id) AS failed,
COUNT(id) FILTER (WHERE "finished_at" > NOW() - INTERVAL '1 HOUR') AS last_1_hour,
COUNT(id) FILTER (WHERE "finished_at" > NOW() - INTERVAL '3 HOURS') AS last_3_hours,
COUNT(id) FILTER (WHERE "finished_at" > NOW() - INTERVAL '24 HOURS') AS last_24_hours,
COUNT(id) FILTER (WHERE "finished_at" > NOW() - INTERVAL '3 DAYS') AS last_3_days,
COUNT(id) FILTER (WHERE "finished_at" > NOW() - INTERVAL '7 DAYS') AS last_7_days
SQL
.order(:exception_class)
.group(:exception_class)

@discarded_jobs_grouped_by_class =
GoodJob::Job.discarded
.select(<<-SQL.squish)
job_class,
count(id) AS failed,
COUNT(*) FILTER (WHERE "finished_at" > NOW() - INTERVAL '1 HOUR') AS last_1_hour,
COUNT(*) FILTER (WHERE "finished_at" > NOW() - INTERVAL '3 HOURS') AS last_3_hours,
COUNT(*) FILTER (WHERE "finished_at" > NOW() - INTERVAL '24 HOURS') AS last_24_hours,
COUNT(*) FILTER (WHERE "finished_at" > NOW() - INTERVAL '3 DAYS') AS last_3_days,
COUNT(*) FILTER (WHERE "finished_at" > NOW() - INTERVAL '7 DAYS') AS last_7_days
SQL
.order(:job_class)
.group(:job_class)
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/good_job/metrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ def primary_nav
batches_count = GoodJob::BatchRecord.all.size
cron_entries_count = GoodJob::CronEntry.all.size
processes_count = GoodJob::Process.active.count
discarded_count = GoodJob::Job.discarded.count

render json: {
jobs_count: helpers.number_to_human(jobs_count),
batches_count: helpers.number_to_human(batches_count),
cron_entries_count: helpers.number_to_human(cron_entries_count),
processes_count: helpers.number_to_human(processes_count),
discarded_count: helpers.number_to_human(discarded_count),
}
end

Expand Down
1 change: 1 addition & 0 deletions app/filters/good_job/base_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def to_params(override = {})
query: params[:query],
state: params[:state],
cron_key: params[:cron_key],
finished_since: params[:finished_since],
}.merge(override).delete_if { |_, v| v.blank? }
end

Expand Down
16 changes: 16 additions & 0 deletions app/filters/good_job/jobs_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def filtered_query(filter_params = params)
query = query.where(queue_name: filter_params[:queue_name]) if filter_params[:queue_name].present?
query = query.search_text(filter_params[:query]) if filter_params[:query].present?
query = query.where(cron_key: filter_params[:cron_key]) if filter_params[:cron_key].present?
query = query.where(finished_at: finished_since(filter_params[:finished_since])..) if filter_params[:finished_since].present?

if filter_params[:state]
case filter_params[:state]
Expand Down Expand Up @@ -61,5 +62,20 @@ def query_for_records
def default_base_query
GoodJob::Job.all
end

def finished_since(finished_since)
case finished_since
when '1_hour_ago'
1.hour.ago
when '3_hours_ago'
3.hours.ago
when '24_hours_ago'
24.hours.ago
when '3_days_ago'
3.days.ago
when '7_days_ago'
7.days.ago
end
end
end
end
85 changes: 85 additions & 0 deletions app/views/good_job/cleaner/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<div class="border-bottom">
<h2 class="pt-3 pb-2"><%= t ".title" %></h2>
</div>

<div>
<h4 class="pt-3 pb-2"><%= t ".grouped_by_class" %></h4>
<table class="table align-middle" id="by-job-class">
<thead>
<tr>
<th scope="col" class="col-3"><%= t ".class" %></th>
<th scope="col" class="text-center"><%= t ".all" %></th>
<th scope="col" class="text-center"><%= t ".last_1_hour" %></th>
<th scope="col" class="text-center"><%= t ".last_3_hours" %></th>
<th scope="col" class="text-center"><%= t ".last_24_hours" %></th>
<th scope="col" class="text-center"><%= t ".last_3_days" %></th>
<th scope="col" class="text-center"><%= t ".last_7_days" %></th>
</tr>
</thead>
<tbody>
<% @discarded_jobs_grouped_by_class.each do |discard_job| %>
<tr>
<td scope="row" class="col-3 text-break"><%= discard_job.job_class %></td>
<td class="text-center "><%= link_to discard_job.failed, jobs_path(@filter.to_params(job_class: discard_job.job_class, state: 'discarded')) %></td>
<td class="text-center"><%= link_to discard_job.last_1_hour, jobs_path(@filter.to_params(job_class: discard_job.job_class, state: 'discarded', finished_since: '1_hour_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_3_hours, jobs_path(@filter.to_params(job_class: discard_job.job_class, state: 'discarded', finished_since: '3_hours_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_24_hours, jobs_path(@filter.to_params(job_class: discard_job.job_class, state: 'discarded', finished_since: '24_hours_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_3_days, jobs_path(@filter.to_params(job_class: discard_job.job_class, state: 'discarded', finished_since: '3_days_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_7_days, jobs_path(@filter.to_params(job_class: discard_job.job_class, state: 'discarded', finished_since: '7_days_ago')) %></td>
</tr>
<% end %>
</tbody>
<tfoot>
<tr>
<td scope="row" class="col-3 fw-bold"><%= t ".total" %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_class.sum(&:failed), jobs_path(@filter.to_params(state: 'discarded')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_class.sum(&:last_1_hour), jobs_path(@filter.to_params(state: 'discarded', finished_since: '1_hour_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_class.sum(&:last_3_hours), jobs_path(@filter.to_params(state: 'discarded', finished_since: '3_hours_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_class.sum(&:last_24_hours), jobs_path(@filter.to_params(state: 'discarded', finished_since: '24_hours_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_class.sum(&:last_3_days), jobs_path(@filter.to_params(state: 'discarded', finished_since: '3_days_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_class.sum(&:last_7_days), jobs_path(@filter.to_params(state: 'discarded', finished_since: '7_days_ago')) %></td>
</tr>
</tfoot>
</table>
</div>

<div>
<h4 class="pt-3 pb-2"><%= t ".grouped_by_exception" %></h4>
<table class="table align-middle" id="by-exception">
<thead>
<tr>
<th scope="col" class="col-3"><%= t ".exception" %></th>
<th scope="col" class="text-center"><%= t ".all" %></th>
<th scope="col" class="text-center"><%= t ".last_1_hour" %></th>
<th scope="col" class="text-center"><%= t ".last_3_hours" %></th>
<th scope="col" class="text-center"><%= t ".last_24_hours" %></th>
<th scope="col" class="text-center"><%= t ".last_3_days" %></th>
<th scope="col" class="text-center"><%= t ".last_7_days" %></th>
</tr>
</thead>
<tbody>
<% @discarded_jobs_grouped_by_exception.each do |discard_job| %>
<tr>
<td scope="row" class="col-3 text-break"><%= discard_job.exception_class %></td>
<td class="text-center"><%= link_to discard_job.failed, jobs_path(@filter.to_params(state: 'discarded', query: discard_job.exception_class)) %></td>
<td class="text-center"><%= link_to discard_job.last_1_hour, jobs_path(@filter.to_params(state: 'discarded', query: discard_job.exception_class, finished_since: '1_hour_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_3_hours, jobs_path(@filter.to_params(state: 'discarded', query: discard_job.exception_class, finished_since: '3_hours_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_24_hours, jobs_path(@filter.to_params(state: 'discarded', query: discard_job.exception_class, finished_since: '24_hours_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_3_days, jobs_path(@filter.to_params(state: 'discarded', query: discard_job.exception_class, finished_since: '3_days_ago')) %></td>
<td class="text-center"><%= link_to discard_job.last_7_days, jobs_path(@filter.to_params(state: 'discarded', query: discard_job.exception_class, finished_since: '7_days_ago')) %></td>
</tr>
<% end %>
</tbody>
<tfoot>
<tr>
<td scope="row" class="col-3 fw-bold"><%= t ".total" %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_exception.sum(&:failed), jobs_path(@filter.to_params(state: 'discarded')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_exception.sum(&:last_1_hour), jobs_path(@filter.to_params(state: 'discarded', finished_since: '1_hour_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_exception.sum(&:last_3_hours), jobs_path(@filter.to_params(state: 'discarded', finished_since: '3_hours_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_exception.sum(&:last_24_hours), jobs_path(@filter.to_params(state: 'discarded', finished_since: '24_hours_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_exception.sum(&:last_3_days), jobs_path(@filter.to_params(state: 'discarded', finished_since: '3_days_ago')) %></td>
<td class="text-center fw-bold"><%= link_to @discarded_jobs_grouped_by_exception.sum(&:last_7_days), jobs_path(@filter.to_params(state: 'discarded', finished_since: '7_days_ago')) %></td>
</tr>
</tfoot>
</table>
</div>
6 changes: 6 additions & 0 deletions app/views/good_job/shared/_navbar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<%= t(".performance") %>
<% end %>
</li>
<li class="nav-item">
<%= link_to cleaner_index_path, class: ["nav-link", ("active" if controller_name == 'cleaner')] do %>
<%= t(".cleaner") %>
<span data-async-values-target="value" data-async-values-key="discarded_count" class="badge bg-secondary rounded-pill d-none"></span>
<% end %>
</li>
</ul>

<ul class="navbar-nav">
Expand Down
15 changes: 15 additions & 0 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ de:
callback_jobs: Callback-Jobs
table:
no_batches_found: Keine Batches gefunden.
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: Bist du sicher, dass du diesen Cron-Eintrag deaktivieren willst?
Expand Down Expand Up @@ -236,6 +250,7 @@ de:
search: Suchen
navbar:
batches: Batches
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: Jobs
live_poll: Live Poll
Expand Down
15 changes: 15 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ en:
callback_jobs: Callback Jobs
table:
no_batches_found: No batches found.
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: Are you sure you want to disable this cron entry?
Expand Down Expand Up @@ -236,6 +250,7 @@ en:
search: Search
navbar:
batches: Batches
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: Jobs
live_poll: Live Poll
Expand Down
15 changes: 15 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ es:
callback_jobs: Callback Jobs
table:
no_batches_found: No hay lotes.
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: "¿Estás seguro que querés deshabilitar esta tarea programada?"
Expand Down Expand Up @@ -236,6 +250,7 @@ es:
search: Buscar
navbar:
batches: Lotes
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: Tareas
live_poll: En vivo
Expand Down
15 changes: 15 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ fr:
callback_jobs: Jobs de rappel
table:
no_batches_found: Aucun lot trouvé.
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: Voulez-vous vraiment désactiver cette entrée cron ?
Expand Down Expand Up @@ -236,6 +250,7 @@ fr:
search: Rechercher
navbar:
batches: Lots
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: Jobs
live_poll: En direct
Expand Down
15 changes: 15 additions & 0 deletions config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ it:
callback_jobs: Job di callback
table:
no_batches_found: Nessun batch trovato.
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: Sei sicuro di voler disabilitare questa voce cron?
Expand Down Expand Up @@ -236,6 +250,7 @@ it:
search: Cerca
navbar:
batches: Batch
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: Job
live_poll: Live Poll
Expand Down
15 changes: 15 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ ja:
callback_jobs: コールバックジョブ
table:
no_batches_found: バッチが見つかりませんでした。
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: このcronエントリを無効化してもよろしいですか?
Expand Down Expand Up @@ -236,6 +250,7 @@ ja:
search: 検索
navbar:
batches: バッチ
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: ジョブ
live_poll: リアルタイム更新
Expand Down
15 changes: 15 additions & 0 deletions config/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ ko:
callback_jobs: 콜백 작업
table:
no_batches_found: 배치를 찾을 수 없습니다.
cleaner:
index:
all: All
class: Class
exception: Exception
grouped_by_class: Discards grouped by Class
grouped_by_exception: Discards grouped by Exception
last_1_hour: Last 1 hour
last_24_hours: Last 24 hours
last_3_days: Last 3 days
last_3_hours: Last 3 hours
last_7_days: Last 7 days
title: Discard Cleaner
total: Total
cron_entries:
actions:
confirm_disable: 이 cron 엔트리를 비활성화하시겠습니까?
Expand Down Expand Up @@ -236,6 +250,7 @@ ko:
search: 검색
navbar:
batches: 배치
cleaner: Discard Cleaner
cron_schedules: Cron
jobs: 작업
live_poll: 실시간 업데이트
Expand Down
Loading