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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user