Skip to content

A platform for community discussion. Free, open, simple.

DEV: Rename problem check jobs to avoid namespace clashes (#26073)

Ted Johansson6e95c152edef
diff --git a/app/jobs/regular/problem_check.rb b/app/jobs/regular/run_problem_check.rb
similarity index 91%
rename from app/jobs/regular/problem_check.rb
rename to app/jobs/regular/run_problem_check.rb
index b4596a874c1..f8468290072 100644
--- a/app/jobs/regular/problem_check.rb
+++ b/app/jobs/regular/run_problem_check.rb
@@ -6,14 +6,14 @@ module Jobs
# This job runs a singular scheduled admin check. It is scheduled by
# the ProblemChecks (plural) scheduled job.
- class ProblemCheck < ::Jobs::Base
+ class RunProblemCheck < ::Jobs::Base
sidekiq_options retry: false
def execute(args)
retry_count = args[:retry_count].to_i
identifier = args[:check_identifier].to_sym
- check = ::ProblemCheck[identifier]
+ check = ProblemCheck[identifier]
problems = check.call
raise RetrySignal if problems.present? && retry_count < check.max_retries
@@ -27,7 +27,7 @@ module Jobs
rescue RetrySignal
Jobs.enqueue_in(
check.retry_after,
- :problem_check,
+ :run_problem_check,
args.merge(retry_count: retry_count + 1).stringify_keys,
)
rescue StandardError => err
diff --git a/app/jobs/scheduled/problem_checks.rb b/app/jobs/scheduled/run_problem_checks.rb
similarity index 85%
rename from app/jobs/scheduled/problem_checks.rb
rename to app/jobs/scheduled/run_problem_checks.rb
index 89161925e49..f91f6ad9e01 100644
--- a/app/jobs/scheduled/problem_checks.rb
+++ b/app/jobs/scheduled/run_problem_checks.rb
@@ -4,7 +4,7 @@ module Jobs
# This job runs all of the scheduled problem checks for the admin dashboard
# on a regular basis. To add a problem check, add a new class that inherits
# the `ProblemCheck` base class.
- class ProblemChecks < ::Jobs::Scheduled
+ class RunProblemChecks < ::Jobs::Scheduled
sidekiq_options retry: false
every 10.minutes
@@ -20,7 +20,7 @@ module Jobs
end
scheduled_checks.each do |check|
- Jobs.enqueue(:problem_check, check_identifier: check.identifier.to_s)
+ Jobs.enqueue(:run_problem_check, check_identifier: check.identifier.to_s)
end
end
end
diff --git a/spec/jobs/problem_check_spec.rb b/spec/jobs/run_problem_check_spec.rb
similarity index 81%
rename from spec/jobs/problem_check_spec.rb
rename to spec/jobs/run_problem_check_spec.rb
index 86c6d128045..63e5ff3181b 100644
--- a/spec/jobs/problem_check_spec.rb
+++ b/spec/jobs/run_problem_check_spec.rb
@@ -1,23 +1,23 @@
# frozen_string_literal: true
-RSpec.describe Jobs::ProblemCheck do
+RSpec.describe Jobs::RunProblemCheck do
after do
Discourse.redis.flushdb
- ::ProblemCheck.send(:remove_const, "TestCheck")
+ ProblemCheck.send(:remove_const, "TestCheck")
end
context "when there are problems" do
before do
- ::ProblemCheck::TestCheck =
- Class.new(::ProblemCheck) do
+ ProblemCheck::TestCheck =
+ Class.new(ProblemCheck) do
self.perform_every = 30.minutes
self.max_retries = 0
def call
[
- ::ProblemCheck::Problem.new("Big problem"),
- ::ProblemCheck::Problem.new(
+ ProblemCheck::Problem.new("Big problem"),
+ ProblemCheck::Problem.new(
"Yuge problem",
priority: "high",
identifier: "config_is_a_mess",
@@ -38,19 +38,19 @@ RSpec.describe Jobs::ProblemCheck do
context "with multiple problems with the same identifier" do
before do
- ::ProblemCheck::TestCheck =
- Class.new(::ProblemCheck) do
+ ProblemCheck::TestCheck =
+ Class.new(ProblemCheck) do
self.perform_every = 30.minutes
self.max_retries = 0
def call
[
- ::ProblemCheck::Problem.new(
+ ProblemCheck::Problem.new(
"Yuge problem",
priority: "high",
identifier: "config_is_a_mess",
),
- ::ProblemCheck::Problem.new(
+ ProblemCheck::Problem.new(
"Nasty problem",
priority: "high",
identifier: "config_is_a_mess",
@@ -71,13 +71,13 @@ RSpec.describe Jobs::ProblemCheck do
context "when there are retries remaining" do
before do
- ::ProblemCheck::TestCheck =
- Class.new(::ProblemCheck) do
+ ProblemCheck::TestCheck =
+ Class.new(ProblemCheck) do
self.perform_every = 30.minutes
self.max_retries = 2
def call
- [::ProblemCheck::Problem.new("Yuge problem")]
+ [ProblemCheck::Problem.new("Yuge problem")]
end
end
end
@@ -101,13 +101,13 @@ RSpec.describe Jobs::ProblemCheck do
context "when there are no retries remaining" do
before do
- ::ProblemCheck::TestCheck =
- Class.new(::ProblemCheck) do
+ ProblemCheck::TestCheck =
+ Class.new(ProblemCheck) do
self.perform_every = 30.minutes
self.max_retries = 1
def call
- [::ProblemCheck::Problem.new("Yuge problem")]
+ [ProblemCheck::Problem.new("Yuge problem")]
end
end
end
@@ -127,8 +127,8 @@ RSpec.describe Jobs::ProblemCheck do
context "when the check unexpectedly errors out" do
before do
- ::ProblemCheck::TestCheck =
- Class.new(::ProblemCheck) do
+ ProblemCheck::TestCheck =
+ Class.new(ProblemCheck) do
self.max_retries = 1
def call
diff --git a/spec/jobs/problem_checks_spec.rb b/spec/jobs/run_problem_checks_spec.rb
similarity index 87%
rename from spec/jobs/problem_checks_spec.rb
rename to spec/jobs/run_problem_checks_spec.rb
index 40c42b4fdfa..92477424eb3 100644
--- a/spec/jobs/problem_checks_spec.rb
+++ b/spec/jobs/run_problem_checks_spec.rb
@@ -1,15 +1,15 @@
# frozen_string_literal: true
-RSpec.describe Jobs::ProblemChecks do
+RSpec.describe Jobs::RunProblemChecks do
before do
- ::ProblemCheck::ScheduledCheck =
+ ProblemCheck::ScheduledCheck =
Class.new(ProblemCheck) do
self.perform_every = 30.minutes
def call = []
end
- ::ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
+ ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
end
after do
@@ -39,7 +39,7 @@ RSpec.describe Jobs::ProblemChecks do
it "does not schedule any check" do
expect_not_enqueued_with(
- job: :problem_check,
+ job: :run_problem_check,
args: {
check_identifier: "scheduled_check",
},
@@ -52,7 +52,7 @@ RSpec.describe Jobs::ProblemChecks do
it "does not schedule any check" do
expect_not_enqueued_with(
- job: :problem_check,
+ job: :run_problem_check,
args: {
check_identifier: "non_scheduled_check",
},
@@ -62,7 +62,7 @@ RSpec.describe Jobs::ProblemChecks do
it "does not schedule non-scheduled checks" do
expect_not_enqueued_with(
- job: :problem_check,
+ job: :run_problem_check,
args: {
check_identifier: "non_scheduled_check",
},