mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Add DB backed problem checks to support perform_every config (#25834)
As part of problem checks refactoring, we're moving some data to be DB backed. In this PR it's the tracking of problem check execution. When was it last run, when was the last problem, when should it run next, how many consecutive checks had problems, etc. This allows us to implement the perform_every feature in scheduled problem checks for checks that don't need to be run every 10 minutes.
This commit is contained in:
@@ -11,6 +11,7 @@ RSpec.describe Jobs::ProblemCheck do
|
||||
before do
|
||||
::ProblemCheck::TestCheck =
|
||||
Class.new(::ProblemCheck) do
|
||||
self.perform_every = 30.minutes
|
||||
self.max_retries = 0
|
||||
|
||||
def call
|
||||
@@ -39,6 +40,7 @@ RSpec.describe Jobs::ProblemCheck do
|
||||
before do
|
||||
::ProblemCheck::TestCheck =
|
||||
Class.new(::ProblemCheck) do
|
||||
self.perform_every = 30.minutes
|
||||
self.max_retries = 0
|
||||
|
||||
def call
|
||||
@@ -71,6 +73,7 @@ RSpec.describe Jobs::ProblemCheck do
|
||||
before do
|
||||
::ProblemCheck::TestCheck =
|
||||
Class.new(::ProblemCheck) do
|
||||
self.perform_every = 30.minutes
|
||||
self.max_retries = 2
|
||||
|
||||
def call
|
||||
@@ -79,6 +82,12 @@ RSpec.describe Jobs::ProblemCheck do
|
||||
end
|
||||
end
|
||||
|
||||
it "does not yet update the problem check tracker" do
|
||||
expect {
|
||||
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
||||
}.not_to change { ProblemCheckTracker.where("blips > ?", 0).count }
|
||||
end
|
||||
|
||||
it "schedules a retry" do
|
||||
expect_enqueued_with(
|
||||
job: :problem_check,
|
||||
@@ -94,6 +103,7 @@ RSpec.describe Jobs::ProblemCheck do
|
||||
before do
|
||||
::ProblemCheck::TestCheck =
|
||||
Class.new(::ProblemCheck) do
|
||||
self.perform_every = 30.minutes
|
||||
self.max_retries = 1
|
||||
|
||||
def call
|
||||
@@ -102,9 +112,15 @@ RSpec.describe Jobs::ProblemCheck do
|
||||
end
|
||||
end
|
||||
|
||||
it "updates the problem check tracker" do
|
||||
expect {
|
||||
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
||||
}.to change { ProblemCheckTracker.where("blips > ?", 0).count }.by(1)
|
||||
end
|
||||
|
||||
it "does not schedule a retry" do
|
||||
expect_not_enqueued_with(job: :problem_check) do
|
||||
described_class.new.execute(check_identifier: :test_identifier, retry_count: 1)
|
||||
described_class.new.execute(check_identifier: :test_check, retry_count: 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,9 +20,43 @@ RSpec.describe Jobs::ProblemChecks do
|
||||
ProblemCheck.send(:remove_const, "NonScheduledCheck")
|
||||
end
|
||||
|
||||
it "schedules the individual scheduled checks" do
|
||||
expect_enqueued_with(job: :problem_check, args: { check_identifier: "scheduled_check" }) do
|
||||
described_class.new.execute([])
|
||||
context "when the tracker determines the check is ready to run" do
|
||||
before do
|
||||
ProblemCheckTracker.create!(identifier: "scheduled_check", next_run_at: 5.minutes.ago)
|
||||
end
|
||||
|
||||
it "schedules the individual scheduled checks" do
|
||||
expect_enqueued_with(job: :problem_check, args: { check_identifier: "scheduled_check" }) do
|
||||
described_class.new.execute([])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when the tracker determines the check shouldn't run yet" do
|
||||
before do
|
||||
ProblemCheckTracker.create!(identifier: "scheduled_check", next_run_at: 5.minutes.from_now)
|
||||
end
|
||||
|
||||
it "does not schedule any check" do
|
||||
expect_not_enqueued_with(
|
||||
job: :problem_check,
|
||||
args: {
|
||||
check_identifier: "scheduled_check",
|
||||
},
|
||||
) { described_class.new.execute([]) }
|
||||
end
|
||||
end
|
||||
|
||||
context "when dealing with a non-scheduled check" do
|
||||
before { ProblemCheckTracker.create!(identifier: "non_scheduled_check", next_run_at: nil) }
|
||||
|
||||
it "does not schedule any check" do
|
||||
expect_not_enqueued_with(
|
||||
job: :problem_check,
|
||||
args: {
|
||||
check_identifier: "non_scheduled_check",
|
||||
},
|
||||
) { described_class.new.execute([]) }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -34,13 +68,4 @@ RSpec.describe Jobs::ProblemChecks do
|
||||
},
|
||||
) { described_class.new.execute([]) }
|
||||
end
|
||||
|
||||
it "does not schedule non-scheduled checks" do
|
||||
expect_not_enqueued_with(
|
||||
job: :problem_check,
|
||||
args: {
|
||||
check_identifier: "non_scheduled_check",
|
||||
},
|
||||
) { described_class.new.execute([]) }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user