diff --git a/app/controllers/delayed_jobs_controller.rb b/app/controllers/delayed_jobs_controller.rb index d011d6476..3b376e918 100644 --- a/app/controllers/delayed_jobs_controller.rb +++ b/app/controllers/delayed_jobs_controller.rb @@ -4,31 +4,31 @@ class DelayedJobsController < ApplicationController respond_to :html, :xml, :json, :js def index - @delayed_jobs = authorize Delayed::Job.order("run_at asc").extending(PaginationExtension).paginate(params[:page], :limit => params[:limit]), policy_class: DelayedJobPolicy - respond_with(@delayed_jobs) + @jobs = authorize GoodJob::ActiveJobJob.order(created_at: :desc).extending(PaginationExtension).paginate(params[:page], limit: params[:limit]), policy_class: GoodJobPolicy + respond_with(@jobs) end def cancel - @job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy - @job.fail! unless @job.locked_at? + @job = authorize GoodJob::ActiveJobJob.find(params[:id]), policy_class: GoodJobPolicy + @job.discard_job("Canceled") respond_with(@job) end def retry - @job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy - @job.update(failed_at: nil, attempts: 0) unless @job.locked_at? + @job = authorize GoodJob::ActiveJobJob.find(params[:id]), policy_class: GoodJobPolicy + @job.retry_job respond_with(@job) end def run - @job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy - @job.update(run_at: Time.zone.now) unless @job.locked_at? + @job = authorize GoodJob::ActiveJobJob.find(params[:id]), policy_class: GoodJobPolicy + @job.reschedule_job respond_with(@job) end def destroy - @job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy - @job.destroy unless @job.locked_at? + @job = authorize GoodJob::ActiveJobJob.find(params[:id]), policy_class: GoodJobPolicy + @job.destroy respond_with(@job) end end diff --git a/app/helpers/delayed_jobs_helper.rb b/app/helpers/delayed_jobs_helper.rb deleted file mode 100644 index 316f0f8ba..000000000 --- a/app/helpers/delayed_jobs_helper.rb +++ /dev/null @@ -1,131 +0,0 @@ -# frozen_string_literal: true - -module DelayedJobsHelper - def print_name(job) - case job.name - when "Tag.increment_post_counts" - "increment post counts" - - when "Tag.decrement_post_counts" - "decrement post counts" - - when "Post.expire_cache" - "expire post cache" - - when "Moderator::TagBatchChange" - "tag batch change" - - when "Class#expire_cache" - "expire post count cache" - - when "Upload#process!" - "upload post" - - when "Tag#update_related" - "update related tags" - - when "TagAlias#process!" - "alias" - - when "TagImplication#process!" - "implication" - - when "Class#clear_cache_for" - "expire tag alias cache" - - when "Tag#update_category_cache" - "update tag category cache" - - when "Tag#update_category_post_counts" - "update category post counts" - - when "Class#remove_iqdb" - "remove from iqdb" - - when "Post#update_iqdb" - "update iqdb" - - when "Class#convert" - "convert ugoira" - - when "Class#increment_post_counts" - "increment post counts" - - when "Class#decrement_post_counts" - "decrement post counts" - - when "Pool#update_category_pseudo_tags_for_posts" - "update pool category pseudo tags for posts" - - when "Post.delete_files" - "delete old files" - - when "BulkRevert#process" - "bulk revert" - - else - h(job.name) - end - end - - def print_handler(job) - case job.name - when "Tag.increment_post_counts", "Tag.decrement_post_counts" - "" - - when "Post.expire_cache" - "" - - when "Moderator::TagBatchChange" - h(job.payload_object.antecedent) + " -> " + h(job.payload_object.consequent) - - when "Class#expire_cache" - h(job.payload_object.args.flatten.join(" ")) - - when "Upload#process!" - %{record} - - when "Tag#update_related" - h(job.payload_object.name) - - when "TagAlias#process!" - h(job.payload_object.antecedent_name) + " -> " + h(job.payload_object.consequent_name) - - when "TagImplication#process!" - h(job.payload_object.antecedent_name) + " -> " + h(job.payload_object.consequent_name) - - when "Class#clear_cache_for" - h(job.payload_object.args.flatten.join(" ")) - - when "Tag#update_category_cache" - h(job.payload_object.name) - - when "Tag#update_category_post_counts" - h(job.payload_object.name) - - when "Class#process", "Class#remove_iqdb" - h(job.payload_object.args.flatten.join(" ")) - - when "Post#update_iqdb" - h(job.payload_object.id) - - when "Class#convert" - h(job.payload_object.args[0]) - - when "Class#increment_post_counts" - h(job.payload_object.args.join(" ")) - - when "Class#decrement_post_counts" - h(job.payload_object.args.join(" ")) - - when "Pool#update_category_pseudo_tags_for_posts" - %{#{h(job.payload_object.name)}} - - when "Post.delete_files" - %{post ##{job.payload_object.args.first}} - - when "BulkRevert#process" - h(job.payload_object.args.join(" ")) - end - end -end diff --git a/app/policies/delayed_job_policy.rb b/app/policies/good_job_policy.rb similarity index 75% rename from app/policies/delayed_job_policy.rb rename to app/policies/good_job_policy.rb index bcfdd6e0b..bcc822b0f 100644 --- a/app/policies/delayed_job_policy.rb +++ b/app/policies/good_job_policy.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true -class DelayedJobPolicy < ApplicationPolicy +class GoodJobPolicy < ApplicationPolicy + def index? + true + end + def update? user.is_admin? end diff --git a/app/views/delayed_jobs/index.html.erb b/app/views/delayed_jobs/index.html.erb index a6c2ef44d..5a07b6990 100644 --- a/app/views/delayed_jobs/index.html.erb +++ b/app/views/delayed_jobs/index.html.erb @@ -2,42 +2,41 @@