Class: GoodJob::JobsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- GoodJob::JobsController
- Defined in:
- app/controllers/good_job/jobs_controller.rb
Constant Summary collapse
- DISCARD_MESSAGE =
"Discarded through dashboard"
- FORCE_DISCARD_MESSAGE =
"Force discarded through dashboard"
- ACTIONS =
{ discard: "discarded", reschedule: "rescheduled", retry: "retried", destroy: "destroyed", }.freeze
Instance Method Summary collapse
- #destroy ⇒ Object
- #discard ⇒ Object
- #force_discard ⇒ Object
- #index ⇒ Object
- #mass_update ⇒ Object
- #redirect_to_index ⇒ Object
- #reschedule ⇒ Object
- #retry ⇒ Object
- #show ⇒ Object
Instance Method Details
#destroy ⇒ Object
91 92 93 94 95 |
# File 'app/controllers/good_job/jobs_controller.rb', line 91 def destroy @job = Job.find(params[:id]) @job.destroy_job redirect_to jobs_path, notice: t(".notice") end |
#discard ⇒ Object
67 68 69 70 71 |
# File 'app/controllers/good_job/jobs_controller.rb', line 67 def discard @job = Job.find(params[:id]) @job.discard_job(DISCARD_MESSAGE) redirect_back(fallback_location: jobs_path, notice: t(".notice")) end |
#force_discard ⇒ Object
73 74 75 76 77 |
# File 'app/controllers/good_job/jobs_controller.rb', line 73 def force_discard @job = Job.find(params[:id]) @job.force_discard_job(FORCE_DISCARD_MESSAGE) redirect_back(fallback_location: jobs_path, notice: t(".notice")) end |
#index ⇒ Object
19 20 21 |
# File 'app/controllers/good_job/jobs_controller.rb', line 19 def index @filter = JobsFilter.new(params) end |
#mass_update ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 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 60 61 |
# File 'app/controllers/good_job/jobs_controller.rb', line 23 def mass_update mass_action = params.fetch(:mass_action, "").to_sym raise ActionController::BadRequest, "#{mass_action} is not a valid mass action" unless mass_action.in?(ACTIONS.keys) jobs = if params[:all_job_ids] JobsFilter.new(params).filtered_query else job_ids = params.fetch(:job_ids, []) Job.where(active_job_id: job_ids) end processed_jobs = jobs.map do |job| case mass_action when :discard job.discard_job(DISCARD_MESSAGE) when :reschedule job.reschedule_job when :retry job.retry_job when :destroy job.destroy_job end job rescue GoodJob::Job::ActiveJobDeserializationError, GoodJob::Job::ActionForStateMismatchError, GoodJob::AdvisoryLockable::RecordAlreadyAdvisoryLockedError nil end.compact # TODO: Put these messages through I18n notice = if processed_jobs.any? "Successfully #{ACTIONS[mass_action]} #{processed_jobs.count} #{'job'.pluralize(processed_jobs.count)}" else "No jobs were #{ACTIONS[mass_action]}" end redirect_back(fallback_location: jobs_path, notice: notice) end |
#redirect_to_index ⇒ Object
97 98 99 100 101 |
# File 'app/controllers/good_job/jobs_controller.rb', line 97 def redirect_to_index # Redirect to the jobs page, maintaining query parameters. This is # necessary to support the `?poll=1` parameter that enables live polling. redirect_to jobs_path(request.query_parameters) end |
#reschedule ⇒ Object
79 80 81 82 83 |
# File 'app/controllers/good_job/jobs_controller.rb', line 79 def reschedule @job = Job.find(params[:id]) @job.reschedule_job redirect_back(fallback_location: jobs_path, notice: t(".notice")) end |
#retry ⇒ Object
85 86 87 88 89 |
# File 'app/controllers/good_job/jobs_controller.rb', line 85 def retry @job = Job.find(params[:id]) @job.retry_job redirect_back(fallback_location: jobs_path, notice: t(".notice")) end |
#show ⇒ Object
63 64 65 |
# File 'app/controllers/good_job/jobs_controller.rb', line 63 def show @job = Job.includes(:executions).includes_advisory_locks.find(params[:id]) end |