Skip to content

Commit

Permalink
Fix Performance table formatting, change url from performances to s…
Browse files Browse the repository at this point in the history
…ingular `performance` (#1393)
  • Loading branch information
bensheldon committed Jul 6, 2024
1 parent 493f790 commit 3baddb1
Show file tree
Hide file tree
Showing 22 changed files with 39 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/controllers/good_job/performances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions app/models/good_job/base_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions app/models/good_job/discrete_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@
<header class="list-group-item bg-body-tertiary">
<div class="row small text-muted text-uppercase align-items-center">
<div class="col-12 col-lg-4"><%= t ".job_class" %></div>
<div class="col-lg-1 d-none d-lg-block"><%= t ".executions" %></div>
<div class="col-lg-2 d-none d-lg-block"><%= t ".executions" %></div>

<div class="col-lg-1 d-none d-lg-block"><%= t ".average_duration" %></div>
<div class="col-lg-1 d-none d-lg-block"><%= t ".minimum_duration" %></div>
<div class="col-lg-1 d-none d-lg-block"><%= t ".maximum_duration" %></div>
<div class="col-lg-2 d-none d-lg-block"><%= t ".average_duration" %></div>
<div class="col-lg-2 d-none d-lg-block"><%= t ".minimum_duration" %></div>
<div class="col-lg-2 d-none d-lg-block"><%= t ".maximum_duration" %></div>
</div>
</header>

<% @performances.each do |performance| %>
<div role="row" class="list-group-item py-3">
<div class="row align-items-center">
<div class="col-12 col-lg-4"><%= performance.job_class %></div>
<div class="col-6 col-lg-1 text-wrap">
<div class="col-6 col-lg-2 text-wrap">
<div class="d-lg-none small text-muted mt-1"><%= t ".executions" %></div>
<%= performance.executions_count %>
</div>

<div class="col-6 col-lg-1 text-wrap">
<div class="col-6 col-lg-2 text-wrap">
<div class="d-lg-none small text-muted mt-1"><%= t ".average_duration" %></div>
<%= format_duration performance.avg_duration %>
</div>
<div class="col-6 col-lg-1 text-wrap">
<div class="col-6 col-lg-2 text-wrap">
<div class="d-lg-none small text-muted mt-1"><%= t ".minimum_duration" %></div>
<%= format_duration performance.min_duration %>
</div>
<div class="col-6 col-lg-1 text-wrap">
<div class="col-6 col-lg-2 text-wrap">
<div class="d-lg-none small text-muted mt-1"><%= t ".maximum_duration" %></div>
<%= format_duration performance.max_duration %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/good_job/shared/_navbar.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<% end %>
</li>
<li class="nav-item">
<%= link_to performances_path, class: ["nav-link", ("active" if controller_name == 'performances')] do %>
<%= link_to performance_path, class: ["nav-link", ("active" if controller_name == 'performances')] do %>
<%= t(".performances") %>
<% end %>
</li>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ de:
trillion: T
unit: ''
performances:
index:
show:
average_duration: Durchschnittliche Dauer
executions: Hinrichtungen
job_class: Berufsklasse
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ en:
trillion: T
unit: ''
performances:
index:
show:
average_duration: Average duration
executions: Executions
job_class: Job class
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ es:
trillion: T
unit: ''
performances:
index:
show:
average_duration: Duración promedio
executions: Ejecuciones
job_class: clase de trabajo
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/locales/it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ it:
trillion: T
unit: ''
performances:
index:
show:
average_duration: Durata media
executions: Esecuzioni
job_class: Classe di lavoro
Expand Down
2 changes: 1 addition & 1 deletion config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ ja:
trillion: T
unit: ''
performances:
index:
show:
average_duration: 平均所要時間
executions: 処刑
job_class: 職種
Expand Down
2 changes: 1 addition & 1 deletion config/locales/ko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ ko:
trillion: T
unit: ''
performances:
index:
show:
average_duration: 평균 지속 시간
executions: 처형
job_class: 직업군
Expand Down
2 changes: 1 addition & 1 deletion config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ nl:
trillion: T
unit: ''
performances:
index:
show:
average_duration: Gemiddelde duur
executions: Executies
job_class: Functie klasse
Expand Down
2 changes: 1 addition & 1 deletion config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ru:
trillion: Т
unit: ''
performances:
index:
show:
average_duration: Средняя продолжительность
executions: Казни
job_class: Класс работы
Expand Down
2 changes: 1 addition & 1 deletion config/locales/tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ tr:
trillion: Trilyon
unit: ''
performances:
index:
show:
average_duration: Ortalama süre
executions: İnfazlar
job_class: İş sınıfı
Expand Down
2 changes: 1 addition & 1 deletion config/locales/uk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ uk:
trillion: Трлн
unit: ''
performances:
index:
show:
average_duration: Середня тривалість
executions: Страти
job_class: Клас роботи
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
2 changes: 1 addition & 1 deletion lib/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions spec/app/models/good_job/execution_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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
)
Expand Down

0 comments on commit 3baddb1

Please sign in to comment.