Module: CoreDelayedJobsController
- Includes:
- CoreController
- Defined in:
- lib/app/controllers/concerns/core_delayed_jobs_controller.rb
Overview
Manage access to delayed jobs
Instance Method Summary collapse
-
#delayed_job ⇒ Object
Fetch the required job by id.
-
#delayed_jobs ⇒ Object
Find the first jobs for index or deleting all.
-
#delayed_jobs_limit ⇒ Object
Define the limit of jobs to fetch for the index of delete all/resubmit all.
-
#destroy ⇒ Object
Destroy the selected delayed job.
-
#destroy_all ⇒ Object
Destroy all jobs.
-
#index ⇒ Object
Show a list of jobs currently in the system.
-
#resubmit ⇒ Object
Resubmit the delayed job via update method.
-
#resubmit_all ⇒ Object
Resubmit all jobs that have failed.
- #show ⇒ Object
Instance Method Details
#delayed_job ⇒ Object
Fetch the required job by id
85 86 87 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 85 def delayed_job @delayed_job ||= Delayed::Backend::Mongoid::Job.find(params[:id]) end |
#delayed_jobs ⇒ Object
Find the first jobs for index or deleting all
92 93 94 95 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 92 def delayed_jobs @delayed_jobs ||= Delayed::Backend::Mongoid::Job.order_by(locked_by: :desc, priority: :asc, run_at: :asc) .limit(delayed_jobs_limit) end |
#delayed_jobs_limit ⇒ Object
Define the limit of jobs to fetch for the index of delete all/resubmit all
Override this in your project if you want a different limit
102 103 104 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 102 def delayed_jobs_limit 100 end |
#destroy ⇒ Object
Destroy the selected delayed job
72 73 74 75 76 77 78 79 80 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 72 def destroy :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 |
#destroy_all ⇒ Object
Destroy all jobs
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 23 def destroy_all :manage, Delayed::Backend::Mongoid::Job failed_only = params[:failed_only].eql?('true') delayed_jobs.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 |
#index ⇒ Object
Show a list of jobs currently in the system
11 12 13 14 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 11 def index :read, Delayed::Backend::Mongoid::Job delayed_jobs end |
#resubmit ⇒ Object
Resubmit the delayed job via update method
59 60 61 62 63 64 65 66 67 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 59 def resubmit :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 |
#resubmit_all ⇒ Object
Resubmit all jobs that have failed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 41 def resubmit_all :read, Delayed::Backend::Mongoid::Job failed_only = params[:failed_only].eql?('true') delayed_jobs.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 |
#show ⇒ Object
16 17 18 |
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 16 def show delayed_job end |