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

Doing the following renames:

Jobs::ProblemChecks → Jobs::RunProblemChecks
Jobs::ProblemCheck → Jobs::RunProblemCheck

This is to disambiguate the ProblemCheck class name, ease fuzzy finding, and avoid needing to use :: in a bunch of places.
This commit is contained in:
Ted Johansson 2024-03-07 15:26:58 +11:00 committed by GitHub
parent 15ff33ae9e
commit 6e95c152ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 29 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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",
},