Class: SolidStackWeb::StatsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_stack_web/stats_controller.rb

Constant Summary collapse

SORTABLE_COLUMNS =
%w[class_name count avg p50 p95 min max].freeze

Constants inherited from ApplicationController

ApplicationController::PERIOD_DURATIONS

Instance Method Summary collapse

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/solid_stack_web/stats_controller.rb', line 5

def index
  @sort      = params[:sort].presence_in(SORTABLE_COLUMNS) || "p95"
  @direction = params[:direction] == "asc" ? "asc" : "desc"

  jobs   = SolidQueue::Job.where.not(finished_at: nil).select(:class_name, :created_at, :finished_at)
  @stats = build_stats(jobs)
  @stats.sort_by! { |row| row[@sort.to_sym] || 0 }
  @stats.reverse! if @direction == "desc"
end