Sha256: eb3a14c3ae8d9e66202d44c3d7555ef7db3ce100de060bba6c4b6ba5882567c4

Contents?: true

Size: 961 Bytes

Versions: 1

Compression:

Stored size: 961 Bytes

Contents

# frozen_string_literal: true

module GoodJob
  class PausesController < ApplicationController
    before_action :validate_type, only: [:create, :destroy]
    def index
      @paused = GoodJob::Setting.paused
    end

    def create
      pause_type = params[:type].to_sym
      pause_value = params[:value].to_s

      GoodJob::Setting.pause(pause_type => pause_value)
      redirect_to({ action: :index }, notice: "Successfully paused #{params[:type]} '#{params[:value]}'")
    end

    def destroy
      pause_type = params[:type].to_sym
      pause_value = params[:value].to_s

      GoodJob::Setting.unpause(pause_type => pause_value)
      redirect_to({ action: :index }, notice: "Successfully unpaused #{params[:type]} '#{params[:value]}'")
    end

    private

    def validate_type
      return if params[:type].in?(%w[queue job_class label]) && params[:value].to_s.present?

      raise ActionController::BadRequest, "Invalid type"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
good_job-4.8.0 app/controllers/good_job/pauses_controller.rb