mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
15ff33ae9e
commit
6e95c152ed
@ -6,14 +6,14 @@ module Jobs
|
|||||||
|
|
||||||
# This job runs a singular scheduled admin check. It is scheduled by
|
# This job runs a singular scheduled admin check. It is scheduled by
|
||||||
# the ProblemChecks (plural) scheduled job.
|
# the ProblemChecks (plural) scheduled job.
|
||||||
class ProblemCheck < ::Jobs::Base
|
class RunProblemCheck < ::Jobs::Base
|
||||||
sidekiq_options retry: false
|
sidekiq_options retry: false
|
||||||
|
|
||||||
def execute(args)
|
def execute(args)
|
||||||
retry_count = args[:retry_count].to_i
|
retry_count = args[:retry_count].to_i
|
||||||
identifier = args[:check_identifier].to_sym
|
identifier = args[:check_identifier].to_sym
|
||||||
|
|
||||||
check = ::ProblemCheck[identifier]
|
check = ProblemCheck[identifier]
|
||||||
|
|
||||||
problems = check.call
|
problems = check.call
|
||||||
raise RetrySignal if problems.present? && retry_count < check.max_retries
|
raise RetrySignal if problems.present? && retry_count < check.max_retries
|
||||||
@ -27,7 +27,7 @@ module Jobs
|
|||||||
rescue RetrySignal
|
rescue RetrySignal
|
||||||
Jobs.enqueue_in(
|
Jobs.enqueue_in(
|
||||||
check.retry_after,
|
check.retry_after,
|
||||||
:problem_check,
|
:run_problem_check,
|
||||||
args.merge(retry_count: retry_count + 1).stringify_keys,
|
args.merge(retry_count: retry_count + 1).stringify_keys,
|
||||||
)
|
)
|
||||||
rescue StandardError => err
|
rescue StandardError => err
|
@ -4,7 +4,7 @@ module Jobs
|
|||||||
# This job runs all of the scheduled problem checks for the admin dashboard
|
# 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
|
# on a regular basis. To add a problem check, add a new class that inherits
|
||||||
# the `ProblemCheck` base class.
|
# the `ProblemCheck` base class.
|
||||||
class ProblemChecks < ::Jobs::Scheduled
|
class RunProblemChecks < ::Jobs::Scheduled
|
||||||
sidekiq_options retry: false
|
sidekiq_options retry: false
|
||||||
|
|
||||||
every 10.minutes
|
every 10.minutes
|
||||||
@ -20,7 +20,7 @@ module Jobs
|
|||||||
end
|
end
|
||||||
|
|
||||||
scheduled_checks.each do |check|
|
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
|
end
|
||||||
end
|
end
|
@ -1,23 +1,23 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe Jobs::ProblemCheck do
|
RSpec.describe Jobs::RunProblemCheck do
|
||||||
after do
|
after do
|
||||||
Discourse.redis.flushdb
|
Discourse.redis.flushdb
|
||||||
|
|
||||||
::ProblemCheck.send(:remove_const, "TestCheck")
|
ProblemCheck.send(:remove_const, "TestCheck")
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when there are problems" do
|
context "when there are problems" do
|
||||||
before do
|
before do
|
||||||
::ProblemCheck::TestCheck =
|
ProblemCheck::TestCheck =
|
||||||
Class.new(::ProblemCheck) do
|
Class.new(ProblemCheck) do
|
||||||
self.perform_every = 30.minutes
|
self.perform_every = 30.minutes
|
||||||
self.max_retries = 0
|
self.max_retries = 0
|
||||||
|
|
||||||
def call
|
def call
|
||||||
[
|
[
|
||||||
::ProblemCheck::Problem.new("Big problem"),
|
ProblemCheck::Problem.new("Big problem"),
|
||||||
::ProblemCheck::Problem.new(
|
ProblemCheck::Problem.new(
|
||||||
"Yuge problem",
|
"Yuge problem",
|
||||||
priority: "high",
|
priority: "high",
|
||||||
identifier: "config_is_a_mess",
|
identifier: "config_is_a_mess",
|
||||||
@ -38,19 +38,19 @@ RSpec.describe Jobs::ProblemCheck do
|
|||||||
|
|
||||||
context "with multiple problems with the same identifier" do
|
context "with multiple problems with the same identifier" do
|
||||||
before do
|
before do
|
||||||
::ProblemCheck::TestCheck =
|
ProblemCheck::TestCheck =
|
||||||
Class.new(::ProblemCheck) do
|
Class.new(ProblemCheck) do
|
||||||
self.perform_every = 30.minutes
|
self.perform_every = 30.minutes
|
||||||
self.max_retries = 0
|
self.max_retries = 0
|
||||||
|
|
||||||
def call
|
def call
|
||||||
[
|
[
|
||||||
::ProblemCheck::Problem.new(
|
ProblemCheck::Problem.new(
|
||||||
"Yuge problem",
|
"Yuge problem",
|
||||||
priority: "high",
|
priority: "high",
|
||||||
identifier: "config_is_a_mess",
|
identifier: "config_is_a_mess",
|
||||||
),
|
),
|
||||||
::ProblemCheck::Problem.new(
|
ProblemCheck::Problem.new(
|
||||||
"Nasty problem",
|
"Nasty problem",
|
||||||
priority: "high",
|
priority: "high",
|
||||||
identifier: "config_is_a_mess",
|
identifier: "config_is_a_mess",
|
||||||
@ -71,13 +71,13 @@ RSpec.describe Jobs::ProblemCheck do
|
|||||||
|
|
||||||
context "when there are retries remaining" do
|
context "when there are retries remaining" do
|
||||||
before do
|
before do
|
||||||
::ProblemCheck::TestCheck =
|
ProblemCheck::TestCheck =
|
||||||
Class.new(::ProblemCheck) do
|
Class.new(ProblemCheck) do
|
||||||
self.perform_every = 30.minutes
|
self.perform_every = 30.minutes
|
||||||
self.max_retries = 2
|
self.max_retries = 2
|
||||||
|
|
||||||
def call
|
def call
|
||||||
[::ProblemCheck::Problem.new("Yuge problem")]
|
[ProblemCheck::Problem.new("Yuge problem")]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -101,13 +101,13 @@ RSpec.describe Jobs::ProblemCheck do
|
|||||||
|
|
||||||
context "when there are no retries remaining" do
|
context "when there are no retries remaining" do
|
||||||
before do
|
before do
|
||||||
::ProblemCheck::TestCheck =
|
ProblemCheck::TestCheck =
|
||||||
Class.new(::ProblemCheck) do
|
Class.new(ProblemCheck) do
|
||||||
self.perform_every = 30.minutes
|
self.perform_every = 30.minutes
|
||||||
self.max_retries = 1
|
self.max_retries = 1
|
||||||
|
|
||||||
def call
|
def call
|
||||||
[::ProblemCheck::Problem.new("Yuge problem")]
|
[ProblemCheck::Problem.new("Yuge problem")]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -127,8 +127,8 @@ RSpec.describe Jobs::ProblemCheck do
|
|||||||
|
|
||||||
context "when the check unexpectedly errors out" do
|
context "when the check unexpectedly errors out" do
|
||||||
before do
|
before do
|
||||||
::ProblemCheck::TestCheck =
|
ProblemCheck::TestCheck =
|
||||||
Class.new(::ProblemCheck) do
|
Class.new(ProblemCheck) do
|
||||||
self.max_retries = 1
|
self.max_retries = 1
|
||||||
|
|
||||||
def call
|
def call
|
@ -1,15 +1,15 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
RSpec.describe Jobs::ProblemChecks do
|
RSpec.describe Jobs::RunProblemChecks do
|
||||||
before do
|
before do
|
||||||
::ProblemCheck::ScheduledCheck =
|
ProblemCheck::ScheduledCheck =
|
||||||
Class.new(ProblemCheck) do
|
Class.new(ProblemCheck) do
|
||||||
self.perform_every = 30.minutes
|
self.perform_every = 30.minutes
|
||||||
|
|
||||||
def call = []
|
def call = []
|
||||||
end
|
end
|
||||||
|
|
||||||
::ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
|
ProblemCheck::NonScheduledCheck = Class.new(ProblemCheck) { def call = [] }
|
||||||
end
|
end
|
||||||
|
|
||||||
after do
|
after do
|
||||||
@ -39,7 +39,7 @@ RSpec.describe Jobs::ProblemChecks do
|
|||||||
|
|
||||||
it "does not schedule any check" do
|
it "does not schedule any check" do
|
||||||
expect_not_enqueued_with(
|
expect_not_enqueued_with(
|
||||||
job: :problem_check,
|
job: :run_problem_check,
|
||||||
args: {
|
args: {
|
||||||
check_identifier: "scheduled_check",
|
check_identifier: "scheduled_check",
|
||||||
},
|
},
|
||||||
@ -52,7 +52,7 @@ RSpec.describe Jobs::ProblemChecks do
|
|||||||
|
|
||||||
it "does not schedule any check" do
|
it "does not schedule any check" do
|
||||||
expect_not_enqueued_with(
|
expect_not_enqueued_with(
|
||||||
job: :problem_check,
|
job: :run_problem_check,
|
||||||
args: {
|
args: {
|
||||||
check_identifier: "non_scheduled_check",
|
check_identifier: "non_scheduled_check",
|
||||||
},
|
},
|
||||||
@ -62,7 +62,7 @@ RSpec.describe Jobs::ProblemChecks do
|
|||||||
|
|
||||||
it "does not schedule non-scheduled checks" do
|
it "does not schedule non-scheduled checks" do
|
||||||
expect_not_enqueued_with(
|
expect_not_enqueued_with(
|
||||||
job: :problem_check,
|
job: :run_problem_check,
|
||||||
args: {
|
args: {
|
||||||
check_identifier: "non_scheduled_check",
|
check_identifier: "non_scheduled_check",
|
||||||
},
|
},
|
Loading…
Reference in New Issue
Block a user