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



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

def destroy
  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_return_path, notice: "Job discarded." }
    end
  else
    jobs = filtered_scope(model).map(&:job)
    model.discard_all_from_jobs(jobs)
    redirect_to jobs_return_path, notice: "#{jobs.size} #{"job".pluralize(jobs.size)} discarded."
  end
rescue ArgumentError => e
  redirect_to jobs_return_path, alert: e.message
rescue => e
  redirect_to jobs_return_path, 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
# File 'app/controllers/solid_queue_web/jobs_controller.rb', line 5

def index
  scope = job_scope

  respond_to do |format|
    format.html do
      @priority_options = Job::EXECUTION_MODELS[@status].joins(:job)
        .distinct.pluck("solid_queue_jobs.priority").sort
      @pagy, @jobs = pagy(scope)
    end
    format.csv do
      send_data jobs_csv(scope),
                filename: "jobs-#{@status}-#{Date.today}.csv",
                type: "text/csv", disposition: "attachment"
    end
  end
end

#showObject



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

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