Sha256: dfce85823afb18132b6eb151a28b8609ef3946cd6c2dc56f2d5a716cf420138f

Contents?: true

Size: 1.99 KB

Versions: 44

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true

#
# Manage access to delayed jobs
#
module CoreDelayedJobsController
  include CoreController
  #
  # Show a list of jobs currently in the system
  #
  def index
    authorize! :read, Delayed::Backend::Mongoid::Job
    @delayed_jobs = Delayed::Backend::Mongoid::Job.asc(%i[priority run_at]).limit(100)
  end

  def show
    delayed_job
  end

  #
  # Destroy all jobs
  #
  def destroy_all
    authorize! :manage, Delayed::Backend::Mongoid::Job
    failed_only = params[:failed_only].eql?('true')
    Delayed::Backend::Mongoid::Job.each do |job|
      next if failed_only && !job.failed?

      job.destroy
    end
    flash.now[:info] = 'All DelayJobs has been destroyed'
    redirect_to index_path
  rescue StandardError => error
    log_controller_error error, true
    redirect_to index_path
  end

  #
  # Resubmit all jobs that have failed
  #
  def resubmit_all
    authorize! :read, Delayed::Backend::Mongoid::Job
    failed_only = params[:failed_only].eql?('true')
    Delayed::Backend::Mongoid::Job.each do |job|
      next if failed_only && !job.failed?

      job.resubmit
    end
    flash.now[:info] = 'All DelayJobs has been resubmitted'
    redirect_to index_path
  rescue StandardError => error
    log_controller_error error, true
    redirect_to index_path
  end

  #
  # Resubmit the delayed job via update method
  #
  def resubmit
    authorize! :read, delayed_job
    delayed_job.resubmit
    flash.now[:info] = 'DelayJob has been resubmitted'
    redirect_to index_path
  rescue StandardError => error
    log_controller_error error, true
    redirect_to index_path
  end

  #
  # Destroy the selected delayed job
  #
  def destroy
    authorize! :manage, delayed_job
    delayed_job.destroy!
    flash.now[:info] = 'DelayJob has been destroyed'
    redirect_to index_path
  rescue StandardError => error
    log_controller_error error, true
    redirect_to index_path
  end

  private

  def delayed_job
    @delayed_job ||= Delayed::Backend::Mongoid::Job.find(params[:id])
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
web47core-1.0.8 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.7 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.6 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.5 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.4 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.3 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.2 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.1 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-1.0.0 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.9.9 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.9.8 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.9.7 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.9.6 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.9.0 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.8.5 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.8.3 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.8.2 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.8.1 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.8.0 lib/app/controllers/concerns/core_delayed_jobs_controller.rb
web47core-0.7.7 lib/app/controllers/concerns/core_delayed_jobs_controller.rb