Skip to content

Commit

Permalink
Load metrics for job statuses asynchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
binarygit committed Mar 18, 2024
1 parent 35461ea commit 8069fad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions app/controllers/good_job/metrics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ def primary_nav
}
end

def job_status
@filter = JobsFilter.new(params)

render json: @filter.states.transform_values { |count| number_with_delimiter(count) }
end

private

def number_to_human(count)
helpers.number_to_human(count, **helpers.translate_hash("good_job.number.human.decimal_units"))
end

def number_with_delimiter(count)
helpers.number_with_delimiter(count, **helpers.translate_hash('good_job.number.format'))
end
end
end
9 changes: 5 additions & 4 deletions app/views/good_job/shared/_filter.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,17 @@
</div>
<% end %>

<ul data-live-poll-region="filter-tabs" class="nav nav-tabs my-3">
<ul data-controller="async-values" data-async-values-url-value="<%= metrics_job_status_path %>" data-live-poll-region="filter-tabs" class="nav nav-tabs my-3">
<li class="nav-item">
<%= link_to t(".all"), filter.to_params(state: nil), class: "nav-link #{"active" unless params[:state].present?}" %>
</li>

<% filter.states.each do |name, count| %>
<% states = %w[scheduled retried queued running succeeded discarded] %>
<% states.each do |name| %>
<li class="nav-item">
<%= link_to filter.to_params(state: name), class: "nav-link #{"active" if params[:state] == name}" do %>
<%= t(name, scope: 'good_job.status', count: count) %>
<span class="badge bg-primary rounded-pill <%= "bg-secondary" if count == 0 %>"><%= number_with_delimiter(count, t('good_job.number.format')) %></span>
<%= t(name, scope: 'good_job.status') %>
<span data-async-values-target="value", data-async-values-key="<%= name %>" data-async-values-zero-class="bg-secondary" class="badge bg-primary rounded-pill d-none"></span>
<% end %>
</li>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
end
end
get 'jobs/metrics/primary_nav', to: 'metrics#primary_nav', as: :metrics_primary_nav
get 'jobs/metrics/job_status', to: 'metrics#job_status', as: :metrics_job_status

resources :batches, only: %i[index show]

Expand Down

0 comments on commit 8069fad

Please sign in to comment.