Class: SolidQueueWeb::HistoryController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_queue_web/history_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::PERIOD_DURATIONS

Instance Method Summary collapse

Instance Method Details

#indexObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/solid_queue_web/history_controller.rb', line 3

def index
  @queue  = params[:queue].presence
  @search = params[:q].presence
  @period = params[:period].presence_in(PERIOD_DURATIONS.keys)

  scope = SolidQueue::Job.where.not(finished_at: nil)
  scope = scope.where(queue_name: @queue)                                    if @queue.present?
  scope = scope.where("class_name LIKE ?", "%#{@search}%")                  if @search.present?
  scope = scope.where("finished_at >= ?", PERIOD_DURATIONS[@period].ago)    if @period.present?

  respond_to do |format|
    format.html { @pagy, @jobs = pagy(scope.order(finished_at: :desc)) }
    format.csv do
      send_data history_csv(scope),
                filename: "job-history-#{Date.today}.csv",
                type: "text/csv", disposition: "attachment"
    end
  end
end