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}.
|
# A job that runs daily to delete all stale jobs. Spawned by {DanbooruMaintenance}.
|
||||||
class PruneJobsJob < ApplicationJob
|
class PruneJobsJob < ApplicationJob
|
||||||
def perform
|
def perform
|
||||||
GoodJob::ActiveJobJob.where("created_at < ?", 7.days.ago).destroy_all
|
BackgroundJob.where("created_at < ?", 7.days.ago).destroy_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# A BackgroundJob is a job in the good_jobs table. This class is simply an
|
# 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
|
# @see https://github.com/bensheldon/good_job
|
||||||
class BackgroundJob < GoodJob::ActiveJobJob
|
class BackgroundJob < GoodJob::Job
|
||||||
delegate :executions_count, to: :job
|
|
||||||
|
|
||||||
concerning :SearchMethods do
|
concerning :SearchMethods do
|
||||||
class_methods do
|
class_methods do
|
||||||
def default_order
|
def default_order
|
||||||
@@ -62,7 +60,7 @@ class BackgroundJob < GoodJob::ActiveJobJob
|
|||||||
end
|
end
|
||||||
|
|
||||||
def pretty_name
|
def pretty_name
|
||||||
job.job_class.titleize.delete_suffix(" Job")
|
job_class.titleize.delete_suffix(" Job")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :good_job, class: GoodJob::ActiveJobJob do
|
factory :good_job, class: GoodJob::Job do
|
||||||
transient do
|
transient do
|
||||||
job { VacuumDatabaseJob.new }
|
job { VacuumDatabaseJob.new }
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,11 +12,16 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get jobs_path
|
get jobs_path
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "cancel action" do
|
context "cancel action" do
|
||||||
should "work" 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
|
put_auth cancel_job_path(@job), @user, xhr: true
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -24,8 +29,8 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "retry action" do
|
context "retry action" do
|
||||||
should "work" do
|
should "work" do
|
||||||
|
@job.discard_job("Canceled")
|
||||||
@job.head_execution.active_job.class.stubs(:queue_adapter).returns(GoodJob::Adapter.new)
|
@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
|
put_auth retry_job_path(@job), @user, xhr: true
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
@@ -33,7 +38,7 @@ class JobsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
|
|
||||||
context "run action" do
|
context "run action" do
|
||||||
should "work" 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
|
put_auth run_job_path(@job), @user, xhr: true
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user