Sha256: 07f4eec63a457aa9b37b9232ccdd0e550d49dd207b81208937e9ecc09c664500

Contents?: true

Size: 974 Bytes

Versions: 10

Compression:

Stored size: 974 Bytes

Contents

module MissionControl::Jobs::NotFoundRedirections
  extend ActiveSupport::Concern

  included do
    rescue_from(ActiveJob::Errors::JobNotFoundError) do |error|
      redirect_to best_location_for_job_relation(error.job_relation), alert: error.message
    end

    rescue_from(MissionControl::Jobs::Errors::ResourceNotFound) do |error|
      redirect_to best_location_for_resource_not_found_error(error), alert: error.message
    end
  end

  private
    def best_location_for_job_relation(job_relation)
      case
      when job_relation.failed?
        application_jobs_path(@application, :failed)
      when job_relation.queue_name.present?
        application_queue_path(@application, job_relation.queue_name)
      else
        root_path
      end
    end

    def best_location_for_resource_not_found_error(error)
      if error.message.match?(/recurring task/i)
        application_recurring_tasks_path(@application)
      else
        root_url
      end
    end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mission_control-jobs-0.6.0 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.5.0 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.4.0 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.3.3 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.3.2 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.3.1 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.3.0 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.2.2 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.2.1 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb
mission_control-jobs-0.2.0 app/controllers/concerns/mission_control/jobs/not_found_redirections.rb