Previously the page-based (numbered) paginator would always count the total_pages, even in API calls when it wasn't needed. This could be very slow in some cases. Refactor so that total_pages isn't calculated unless it's called. While we're at it, refactor to condense all the sequential vs. numbered pagination logic into one module. This incidentally fixes a couple more bugs: * "page=b0" returned all pages rather than nothing. * Bad parameters like "page=blaha123" and "page=a123blah" were accepted.
42 lines
908 B
Ruby
42 lines
908 B
Ruby
class DelayedJobsController < ApplicationController
|
|
respond_to :html, :xml, :json, :js
|
|
before_action :admin_only, except: [:index]
|
|
|
|
def index
|
|
@delayed_jobs = Delayed::Job.order("run_at asc").extending(PaginationExtension).paginate(params[:page], :limit => params[:limit])
|
|
respond_with(@delayed_jobs)
|
|
end
|
|
|
|
def cancel
|
|
@job = Delayed::Job.find(params[:id])
|
|
if !@job.locked_at?
|
|
@job.fail!
|
|
end
|
|
respond_with(@job)
|
|
end
|
|
|
|
def retry
|
|
@job = Delayed::Job.find(params[:id])
|
|
if !@job.locked_at?
|
|
@job.update(failed_at: nil, attempts: 0)
|
|
end
|
|
respond_with(@job)
|
|
end
|
|
|
|
def run
|
|
@job = Delayed::Job.find(params[:id])
|
|
if !@job.locked_at?
|
|
@job.update(run_at: Time.now)
|
|
end
|
|
respond_with(@job)
|
|
end
|
|
|
|
def destroy
|
|
@job = Delayed::Job.find(params[:id])
|
|
if !@job.locked_at?
|
|
@job.destroy
|
|
end
|
|
respond_with(@job)
|
|
end
|
|
end
|