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

Instance Method Details

#delayed_jobObject

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_jobsObject

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_limitObject

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

#destroyObject

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
  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

#destroy_allObject

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
  authorize! :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

#indexObject

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
  authorize! :read, Delayed::Backend::Mongoid::Job
  delayed_jobs
end

#resubmitObject

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
  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

#resubmit_allObject

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
  authorize! :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

#showObject



16
17
18
# File 'lib/app/controllers/concerns/core_delayed_jobs_controller.rb', line 16

def show
  delayed_job
end