Sha256: 11224848b99b67d01d06c6631085ddea9a914e869278aa08d0907b00251b2d1f

Contents?: true

Size: 1.65 KB

Versions: 2

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true
module GoodJob
  class JobsController < GoodJob::ApplicationController
    rescue_from GoodJob::ActiveJobJob::AdapterNotGoodJobError,
                GoodJob::ActiveJobJob::ActionForStateMismatchError,
                with: :redirect_on_error

    def index
      @filter = JobsFilter.new(params)
    end

    def show
      @executions = GoodJob::Execution.active_job_id(params[:id])
                                      .order(Arel.sql("COALESCE(scheduled_at, created_at) DESC"))
      redirect_to jobs_path, alert: "Executions for Active Job #{params[:id]} not found" if @executions.empty?
    end

    def discard
      @job = ActiveJobJob.find(params[:id])
      @job.discard_job("Discarded through dashboard")
      redirect_back(fallback_location: jobs_path, notice: "Job has been discarded")
    end

    def reschedule
      @job = ActiveJobJob.find(params[:id])
      @job.reschedule_job
      redirect_back(fallback_location: jobs_path, notice: "Job has been rescheduled")
    end

    def retry
      @job = ActiveJobJob.find(params[:id])
      @job.retry_job
      redirect_back(fallback_location: jobs_path, notice: "Job has been retried")
    end

    private

    def redirect_on_error(exception)
      alert = case exception
              when GoodJob::ActiveJobJob::AdapterNotGoodJobError
                "ActiveJob Queue Adapter must be GoodJob."
              when GoodJob::ActiveJobJob::ActionForStateMismatchError
                "Job is not in an appropriate state for this action."
              else
                exception.to_s
              end
      redirect_back(fallback_location: jobs_path, alert: alert)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
good_job-2.13.2 engine/app/controllers/good_job/jobs_controller.rb
good_job-2.13.1 engine/app/controllers/good_job/jobs_controller.rb