Class: SolidQueueWeb::JobsController

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

Constant Summary

Constants inherited from ApplicationController

ApplicationController::PERIOD_DURATIONS, ApplicationController::STAGGER_INTERVALS

Instance Method Summary collapse

Instance Method Details

#destroyObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/solid_queue_web/jobs_controller.rb', line 35

def destroy
  @status   = params[:status]
  @period   = params[:period].presence_in(PERIOD_DURATIONS.keys)
  @priority = params[:priority].presence
  model = Job.execution_model_for!(@status)
  if params[:id]
    @execution = model.find(params[:id])
    @execution.discard
    @remaining_count = filtered_scope(model).count
    respond_to do |format|
      format.turbo_stream
      format.html { redirect_to jobs_path(status: @status, period: @period), notice: "Job discarded." }
    end
  else
    jobs = filtered_scope(model).map(&:job)
    model.discard_all_from_jobs(jobs)
    redirect_to jobs_path(status: @status, period: @period),
      notice: "#{jobs.size} #{"job".pluralize(jobs.size)} discarded."
  end
rescue ArgumentError => e
  redirect_to jobs_path(status: @status, period: @period), alert: e.message
rescue => e
  redirect_to jobs_path(status: @status, period: @period),
    alert: "Could not discard #{params[:id] ? "job" : "jobs"}: #{e.message}"
end

#indexObject



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

def index
  @status   = params[:status].presence_in(Job::STATUSES) || "ready"
  @search   = params[:q].presence
  @period   = params[:period].presence_in(PERIOD_DURATIONS.keys)
  @priority = params[:priority].presence

  scope = Job::EXECUTION_MODELS[@status].includes(:job)
  scope = scope.references(:job).where("solid_queue_jobs.class_name LIKE ?", "%#{@search}%")         if @search.present?
  scope = scope.references(:job).where("solid_queue_jobs.created_at >= ?", PERIOD_DURATIONS[@period].ago) if @period.present?
  scope = scope.references(:job).where("solid_queue_jobs.priority = ?", @priority.to_i)              if @priority.present?
  scope = scope.order(created_at: :desc)

  @priority_options = Job::EXECUTION_MODELS[@status].joins(:job)
    .distinct.pluck("solid_queue_jobs.priority").sort

  respond_to do |format|
    format.html { @pagy, @jobs = pagy(scope) }
    format.csv do
      send_data jobs_csv(scope),
                filename: "jobs-#{@status}-#{Date.today}.csv",
                type: "text/csv", disposition: "attachment"
    end
  end
end

#showObject



28
29
30
31
32
33
# File 'app/controllers/solid_queue_web/jobs_controller.rb', line 28

def show
  @job = SolidQueue::Job
    .includes(:ready_execution, :scheduled_execution, :claimed_execution, :blocked_execution, :failed_execution)
    .find(params[:id])
  @execution_status = Job.derive_status(@job)
end