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

Instance Method Summary collapse

Instance Method Details

#destroyObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/solid_queue_web/jobs_controller.rb', line 31

def destroy
  model = 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



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

def index
  @status = params[:status].presence_in(Job::STATUSES) || "ready"
  @search = params[:q].presence
  @period = params[:period].presence_in(PERIOD_DURATIONS.keys)
  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.order(created_at: :desc)

  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



24
25
26
27
28
29
# File 'app/controllers/solid_queue_web/jobs_controller.rb', line 24

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