diff --git a/app/controllers/good_job/performances_controller.rb b/app/controllers/good_job/performances_controller.rb new file mode 100644 index 000000000..afbcd3f5e --- /dev/null +++ b/app/controllers/good_job/performances_controller.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +module GoodJob + class PerformancesController < ApplicationController + def index + if GoodJob::DiscreteExecution.monotonic_duration_migrated? + @performances = GoodJob::DiscreteExecution + .where.not(job_class: nil) + .group(:job_class) + .select(" + job_class, + COUNT(*) AS executions_count, + AVG(duration) AS avg_duration, + MIN(duration) AS min_duration, + MAX(duration) AS max_duration + ") + .order("job_class") + else + @needs_upgrade = true + end + end + end +end diff --git a/app/helpers/good_job/application_helper.rb b/app/helpers/good_job/application_helper.rb index 39558e6b7..4fa12f4b0 100644 --- a/app/helpers/good_job/application_helper.rb +++ b/app/helpers/good_job/application_helper.rb @@ -9,6 +9,7 @@ module ApplicationHelper def format_duration(sec) return unless sec + return "" if sec.is_a?(String) # pg interval support added in Rails 6.1 if sec < 1 t 'good_job.duration.milliseconds', ms: (sec * 1000).floor diff --git a/app/views/good_job/performances/index.html.erb b/app/views/good_job/performances/index.html.erb new file mode 100644 index 000000000..be0de2475 --- /dev/null +++ b/app/views/good_job/performances/index.html.erb @@ -0,0 +1,50 @@ +
+

<%= t ".title" %>

+
+ +<% if @needs_upgrade %> +
+ <%= t "shared.needs_migration" %> +
+<% else %> + +
+
+
+
+
<%= t ".job_class" %>
+
<%= t ".executions" %>
+ +
<%= t ".average_duration" %>
+
<%= t ".minimum_duration" %>
+
<%= t ".maximum_duration" %>
+
+
+ + <% @performances.each do |performance| %> +
+
+
<%= performance.job_class %>
+
+
<%= t ".executions" %>
+ <%= performance.executions_count %> +
+ +
+
<%= t ".average_duration" %>
+ <%= format_duration performance.avg_duration %> +
+
+
<%= t ".minimum_duration" %>
+ <%= format_duration performance.min_duration %> +
+
+
<%= t ".maximum_duration" %>
+ <%= format_duration performance.max_duration %> +
+
+
+ <% end %> +
+
+<% end %> diff --git a/app/views/good_job/shared/_navbar.erb b/app/views/good_job/shared/_navbar.erb index c4466af03..5229978ca 100644 --- a/app/views/good_job/shared/_navbar.erb +++ b/app/views/good_job/shared/_navbar.erb @@ -39,6 +39,11 @@ <% end %> +