Class: SolidObserver::JobsController

Inherits:
ApplicationController show all
Includes:
Paginatable, RequireSolidQueue
Defined in:
app/controllers/solid_observer/jobs_controller.rb

Constant Summary collapse

PER_PAGE =
25
CACHE_KEY_QUEUES =
"solid_observer/jobs/available_queues"
CACHE_KEY_JOB_CLASSES =
"solid_observer/jobs/available_job_classes"

Instance Method Summary collapse

Methods inherited from ApplicationController

runtime_db_errors

Instance Method Details

#discardObject



45
46
47
48
49
50
51
52
# File 'app/controllers/solid_observer/jobs_controller.rb', line 45

def discard
  id = params[:id]
  execution = Queries::ExecutionFinder.find_failed(id)
  return redirect_to(jobs_path, alert: "Failed job not found") unless execution

  execution.discard
  redirect_to jobs_path(status: "failed"), notice: "Job #{id} discarded"
end

#indexObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/solid_observer/jobs_controller.rb', line 12

def index
  filter = Params::JobsFilter.from_params(params)
  @status = filter.status
  @queue_name = filter.queue_name
  @job_class = filter.job_class
  @page = filter.page
  result = Queries::JobExecutionsQuery.new(filter).call
  offset = paginate_scope(result, per_page: PER_PAGE)
  @jobs = if result.is_a?(Array)
    result.drop(offset).first(PER_PAGE)
  else
    result.limit(PER_PAGE).offset(offset).includes(:job).to_a
  end
  @available_queues = fetch_available_queues
  @available_job_classes = fetch_available_job_classes
end

#retryObject



36
37
38
39
40
41
42
43
# File 'app/controllers/solid_observer/jobs_controller.rb', line 36

def retry
  id = params[:id]
  execution = Queries::ExecutionFinder.find_failed(id)
  return redirect_to(jobs_path, alert: "Failed job not found") unless execution

  execution.retry
  redirect_to jobs_path(status: "failed"), notice: "Job #{id} queued for retry"
end

#showObject



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

def show
  @execution = find_execution_for_show
  return redirect_to jobs_path, alert: "Job not found" unless @execution

  assign_show_presenter
end