From c8917684b86fd9ffa652279c7484ff0df1baab8b Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 23 Aug 2022 17:27:23 -0500 Subject: [PATCH] jobs: fix failures in /jobs controller. Fix errors with searching for and retrying jobs on the /jobs page caused by the upgrade to GoodJob 3.0. --- app/jobs/prune_jobs_job.rb | 2 +- app/models/background_job.rb | 10 ++++------ test/factories/good_job.rb | 2 +- test/functional/jobs_controller_test.rb | 11 ++++++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/app/jobs/prune_jobs_job.rb b/app/jobs/prune_jobs_job.rb index ab67ce95b..f58e5e299 100644 --- a/app/jobs/prune_jobs_job.rb +++ b/app/jobs/prune_jobs_job.rb @@ -3,6 +3,6 @@ # A job that runs daily to delete all stale jobs. Spawned by {DanbooruMaintenance}. class PruneJobsJob < ApplicationJob def perform - GoodJob::ActiveJobJob.where("created_at < ?", 7.days.ago).destroy_all + BackgroundJob.where("created_at < ?", 7.days.ago).destroy_all end end diff --git a/app/models/background_job.rb b/app/models/background_job.rb index 9add90af5..f501a0ba0 100644 --- a/app/models/background_job.rb +++ b/app/models/background_job.rb @@ -1,12 +1,10 @@ # frozen_string_literal: true # A BackgroundJob is a job in the good_jobs table. This class is simply an -# extension of GoodJob::ActiveJobJob, with a few extra methods for searching jobs. +# extension of GoodJob::Job, with a few extra methods for searching jobs. # -# @see https://github.com/bensheldon/good_job/blob/main/lib/good_job/active_job_job.rb -class BackgroundJob < GoodJob::ActiveJobJob - delegate :executions_count, to: :job - +# @see https://github.com/bensheldon/good_job +class BackgroundJob < GoodJob::Job concerning :SearchMethods do class_methods do def default_order @@ -62,7 +60,7 @@ class BackgroundJob < GoodJob::ActiveJobJob end def pretty_name - job.job_class.titleize.delete_suffix(" Job") + job_class.titleize.delete_suffix(" Job") end end end diff --git a/test/factories/good_job.rb b/test/factories/good_job.rb index f85dcefe5..b607bfbdb 100644 --- a/test/factories/good_job.rb +++ b/test/factories/good_job.rb @@ -1,5 +1,5 @@ FactoryBot.define do - factory :good_job, class: GoodJob::ActiveJobJob do + factory :good_job, class: GoodJob::Job do transient do job { VacuumDatabaseJob.new } end diff --git a/test/functional/jobs_controller_test.rb b/test/functional/jobs_controller_test.rb index 387dabb5d..ca73c525f 100644 --- a/test/functional/jobs_controller_test.rb +++ b/test/functional/jobs_controller_test.rb @@ -12,11 +12,16 @@ class JobsControllerTest < ActionDispatch::IntegrationTest get jobs_path assert_response :success end + + should respond_to_search(status: "running").with { [] } + should respond_to_search(status: "queued").with { [@job] } + should respond_to_search(status: "finished").with { [] } + should respond_to_search(status: "discarded").with { [] } end context "cancel action" do should "work" do - GoodJob::ActiveJobJob.any_instance.stubs(:status).returns(:queued) + GoodJob::Job.any_instance.stubs(:status).returns(:queued) put_auth cancel_job_path(@job), @user, xhr: true assert_response :success end @@ -24,8 +29,8 @@ class JobsControllerTest < ActionDispatch::IntegrationTest context "retry action" do should "work" do + @job.discard_job("Canceled") @job.head_execution.active_job.class.stubs(:queue_adapter).returns(GoodJob::Adapter.new) - GoodJob::ActiveJobJob.any_instance.stubs(:status).returns(:discarded) put_auth retry_job_path(@job), @user, xhr: true assert_response :success end @@ -33,7 +38,7 @@ class JobsControllerTest < ActionDispatch::IntegrationTest context "run action" do should "work" do - GoodJob::ActiveJobJob.any_instance.stubs(:status).returns(:queued) + GoodJob::Job.any_instance.stubs(:status).returns(:queued) put_auth run_job_path(@job), @user, xhr: true assert_response :success end