diff --git a/app/controllers/good_job/performances_controller.rb b/app/controllers/good_job/performances_controller.rb index afbcd3f5..1becd93d 100644 --- a/app/controllers/good_job/performances_controller.rb +++ b/app/controllers/good_job/performances_controller.rb @@ -2,8 +2,8 @@ module GoodJob class PerformancesController < ApplicationController - def index - if GoodJob::DiscreteExecution.monotonic_duration_migrated? + def show + if GoodJob::DiscreteExecution.duration_interval_migrated? @performances = GoodJob::DiscreteExecution .where.not(job_class: nil) .group(:job_class) diff --git a/app/models/good_job/base_execution.rb b/app/models/good_job/base_execution.rb index 6e6ed66c..d2be5d58 100644 --- a/app/models/good_job/base_execution.rb +++ b/app/models/good_job/base_execution.rb @@ -494,7 +494,7 @@ def perform(lock_id:) finished_at: job_performed_at, } discrete_execution_attrs[:error_event] = GoodJob::ErrorEvents::ERROR_EVENT_ENUMS[GoodJob::ErrorEvents::ERROR_EVENT_INTERRUPTED] if self.class.error_event_migrated? - discrete_execution_attrs[:duration] = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') + discrete_execution_attrs[:duration] = monotonic_duration if GoodJob::DiscreteExecution.duration_interval_usable? discrete_executions.where(finished_at: nil).where.not(performed_at: nil).update_all(discrete_execution_attrs) # rubocop:disable Rails/SkipsModelValidations end end @@ -602,7 +602,7 @@ def perform(lock_id:) job_attributes[:finished_at] = job_finished_at if discrete_execution discrete_execution.finished_at = job_finished_at - discrete_execution.duration = monotonic_duration if GoodJob::DiscreteExecution.monotonic_duration_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') + discrete_execution.duration = monotonic_duration if GoodJob::DiscreteExecution.duration_interval_usable? end retry_unhandled_error = result.unhandled_error && GoodJob.retry_on_unhandled_error diff --git a/app/models/good_job/discrete_execution.rb b/app/models/good_job/discrete_execution.rb index 56654bd2..f9c913bb 100644 --- a/app/models/good_job/discrete_execution.rb +++ b/app/models/good_job/discrete_execution.rb @@ -28,13 +28,17 @@ def self.backtrace_migrated? false end - def self.monotonic_duration_migrated? + def self.duration_interval_migrated? return true if columns_hash["duration"].present? migration_pending_warning! false end + def self.duration_interval_usable? + duration_interval_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') + end + def number serialized_params.fetch('executions', 0) + 1 end @@ -47,7 +51,7 @@ def queue_latency # Monotonic time between when this job started and finished def runtime_latency # migrated and Rails greater than 6.1 - if self.class.monotonic_duration_migrated? && Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') + if self.class.duration_interval_usable? duration elsif performed_at (finished_at || Time.current) - performed_at diff --git a/app/views/good_job/performances/index.html.erb b/app/views/good_job/performances/show.html.erb similarity index 77% rename from app/views/good_job/performances/index.html.erb rename to app/views/good_job/performances/show.html.erb index be0de247..31f7b553 100644 --- a/app/views/good_job/performances/index.html.erb +++ b/app/views/good_job/performances/show.html.erb @@ -13,11 +13,11 @@
<%= t ".job_class" %>
-
<%= t ".executions" %>
+
<%= t ".executions" %>
-
<%= t ".average_duration" %>
-
<%= t ".minimum_duration" %>
-
<%= t ".maximum_duration" %>
+
<%= t ".average_duration" %>
+
<%= t ".minimum_duration" %>
+
<%= t ".maximum_duration" %>
@@ -25,20 +25,20 @@
<%= 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 %>
diff --git a/app/views/good_job/shared/_navbar.erb b/app/views/good_job/shared/_navbar.erb index 5229978c..c5e357bf 100644 --- a/app/views/good_job/shared/_navbar.erb +++ b/app/views/good_job/shared/_navbar.erb @@ -40,7 +40,7 @@ <% end %> diff --git a/config/locales/de.yml b/config/locales/de.yml index 1468af95..80669f7d 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -197,7 +197,7 @@ de: trillion: T unit: '' performances: - index: + show: average_duration: Durchschnittliche Dauer executions: Hinrichtungen job_class: Berufsklasse diff --git a/config/locales/en.yml b/config/locales/en.yml index dd154f7b..b3666352 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -197,7 +197,7 @@ en: trillion: T unit: '' performances: - index: + show: average_duration: Average duration executions: Executions job_class: Job class diff --git a/config/locales/es.yml b/config/locales/es.yml index c6beac00..a295da32 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -197,7 +197,7 @@ es: trillion: T unit: '' performances: - index: + show: average_duration: Duración promedio executions: Ejecuciones job_class: clase de trabajo diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 36e4093a..e932847a 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -197,7 +197,7 @@ fr: trillion: J unit: '' performances: - index: + show: average_duration: Durée moyenne executions: Exécutions job_class: Catégorie d'emplois diff --git a/config/locales/it.yml b/config/locales/it.yml index a4cad1a7..d93cbe7f 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -197,7 +197,7 @@ it: trillion: T unit: '' performances: - index: + show: average_duration: Durata media executions: Esecuzioni job_class: Classe di lavoro diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 617c7c09..47a2189c 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -197,7 +197,7 @@ ja: trillion: T unit: '' performances: - index: + show: average_duration: 平均所要時間 executions: 処刑 job_class: 職種 diff --git a/config/locales/ko.yml b/config/locales/ko.yml index f6e26778..9a1d2804 100644 --- a/config/locales/ko.yml +++ b/config/locales/ko.yml @@ -197,7 +197,7 @@ ko: trillion: T unit: '' performances: - index: + show: average_duration: 평균 지속 시간 executions: 처형 job_class: 직업군 diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 4e6d15eb..39d72fc7 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -197,7 +197,7 @@ nl: trillion: T unit: '' performances: - index: + show: average_duration: Gemiddelde duur executions: Executies job_class: Functie klasse diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 23fe01b5..a08c997b 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -197,7 +197,7 @@ pt-BR: trillion: T unit: '' performances: - index: + show: average_duration: Duração média executions: Execuções job_class: Classe de trabalho diff --git a/config/locales/ru.yml b/config/locales/ru.yml index e945f679..c4fc173f 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -223,7 +223,7 @@ ru: trillion: Т unit: '' performances: - index: + show: average_duration: Средняя продолжительность executions: Казни job_class: Класс работы diff --git a/config/locales/tr.yml b/config/locales/tr.yml index 6d348b18..29497591 100644 --- a/config/locales/tr.yml +++ b/config/locales/tr.yml @@ -197,7 +197,7 @@ tr: trillion: Trilyon unit: '' performances: - index: + show: average_duration: Ortalama süre executions: İnfazlar job_class: İş sınıfı diff --git a/config/locales/uk.yml b/config/locales/uk.yml index dd9f3704..ac0b22f9 100644 --- a/config/locales/uk.yml +++ b/config/locales/uk.yml @@ -223,7 +223,7 @@ uk: trillion: Трлн unit: '' performances: - index: + show: average_duration: Середня тривалість executions: Страти job_class: Клас роботи diff --git a/config/routes.rb b/config/routes.rb index 13ef5939..ef63ca6b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -31,7 +31,7 @@ resources :processes, only: %i[index] - resources :performances, only: %i[index] + resource :performance, only: %i[show] scope :frontend, controller: :frontends do get "modules/:name", action: :module, as: :frontend_module, constraints: { format: 'js' } diff --git a/lib/good_job.rb b/lib/good_job.rb index 95016d74..fa9ca628 100644 --- a/lib/good_job.rb +++ b/lib/good_job.rb @@ -287,7 +287,7 @@ def self.deprecator def self.migrated? # Always update with the most recent migration check GoodJob::DiscreteExecution.reset_column_information - GoodJob::DiscreteExecution.monotonic_duration_migrated? + GoodJob::DiscreteExecution.duration_interval_migrated? end ActiveSupport.run_load_hooks(:good_job, self) diff --git a/spec/app/controllers/good_job/performances_controller_spec.rb b/spec/app/controllers/good_job/performances_controller_spec.rb index 48aa6a32..122e139e 100644 --- a/spec/app/controllers/good_job/performances_controller_spec.rb +++ b/spec/app/controllers/good_job/performances_controller_spec.rb @@ -14,7 +14,7 @@ describe '#index' do it 'renders the index page' do - get :index + get :show expect(response).to have_http_status(:ok) expect(response.body).to include('Performance') end diff --git a/spec/app/models/good_job/execution_spec.rb b/spec/app/models/good_job/execution_spec.rb index 9853156c..0699d427 100644 --- a/spec/app/models/good_job/execution_spec.rb +++ b/spec/app/models/good_job/execution_spec.rb @@ -702,7 +702,7 @@ def job_params created_at: within(0.001).of(good_job.performed_at), scheduled_at: within(0.001).of(good_job.created_at), finished_at: within(1.second).of(Time.current), - duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil, + duration: GoodJob::DiscreteExecution.duration_interval_usable? ? be_present : nil, error: nil, serialized_params: good_job.serialized_params ) @@ -741,7 +741,7 @@ def job_params created_at: within(1.second).of(Time.current), scheduled_at: within(1.second).of(Time.current), finished_at: within(1.second).of(Time.current), - duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil + duration: GoodJob::DiscreteExecution.duration_interval_usable? ? be_present : nil ) end end @@ -766,7 +766,7 @@ def job_params expect(good_job.discrete_executions.first).to have_attributes( performed_at: within(1.second).of(Time.current), finished_at: within(1.second).of(Time.current), - duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil + duration: GoodJob::DiscreteExecution.duration_interval_usable? ? be_present : nil ) end end diff --git a/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb b/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb index ad92cbf3..b406d4cb 100644 --- a/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb +++ b/spec/lib/good_job/active_job_extensions/interrupt_errors_spec.rb @@ -83,7 +83,7 @@ def perform expect(initial_discrete_execution).to have_attributes( performed_at: be_present, finished_at: be_present, - duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil, + duration: GoodJob::DiscreteExecution.duration_interval_usable? ? be_present : nil, error: start_with('GoodJob::InterruptError: Interrupted after starting perform at'), error_event: GoodJob::Job::ERROR_EVENT_INTERRUPTED ) @@ -92,7 +92,7 @@ def perform expect(retried_discrete_execution).to have_attributes( performed_at: be_present, finished_at: be_present, - duration: Gem::Version.new(Rails.version) >= Gem::Version.new('6.1.0.a') ? be_present : nil, + duration: GoodJob::DiscreteExecution.duration_interval_usable? ? be_present : nil, error: start_with('GoodJob::InterruptError: Interrupted after starting perform at'), error_event: GoodJob::Job::ERROR_EVENT_RETRIED )