mirror of
https://github.com/discourse/discourse.git
synced 2025-10-03 17:21:20 +08:00
FIX: Run scheduled problem checks even when no tracker exists yet (#35102)
### What is this change? Scheduled problem checks without trackers weren't being run. This is because we directly tried to look for trackers instead of going through the checks.
This commit is contained in:
parent
891106d5f4
commit
480e05e67a
3 changed files with 26 additions and 13 deletions
|
@ -10,21 +10,17 @@ module Jobs
|
|||
every 10.minutes
|
||||
|
||||
def execute(_args)
|
||||
scheduled_checks =
|
||||
ProblemCheckTracker.all.filter_map do |tracker|
|
||||
tracker.check if eligible_for_this_run?(tracker)
|
||||
ProblemCheck.scheduled.filter_map do |check|
|
||||
if eligible_for_this_run?(check)
|
||||
Jobs.enqueue(:run_problem_check, check_identifier: check.identifier.to_s)
|
||||
end
|
||||
|
||||
scheduled_checks.each do |check|
|
||||
Jobs.enqueue(:run_problem_check, check_identifier: check.identifier.to_s)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def eligible_for_this_run?(tracker)
|
||||
tracker.check.present? && tracker.check.enabled? && tracker.check.scheduled? &&
|
||||
tracker.ready_to_run?
|
||||
def eligible_for_this_run?(check)
|
||||
check.enabled? && check.scheduled? && check.ready_to_run?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -112,6 +112,11 @@ class ProblemCheck
|
|||
Collection.new(checks.select(&:realtime?))
|
||||
end
|
||||
|
||||
def self.tracker(target = NO_TARGET)
|
||||
ProblemCheckTracker[identifier, target]
|
||||
end
|
||||
delegate :tracker, to: :class
|
||||
|
||||
def self.identifier
|
||||
name.demodulize.underscore.to_sym
|
||||
end
|
||||
|
@ -137,6 +142,11 @@ class ProblemCheck
|
|||
end
|
||||
delegate :inline?, to: :class
|
||||
|
||||
def self.ready_to_run?
|
||||
tracker.ready_to_run?
|
||||
end
|
||||
delegate :ready_to_run?, to: :class
|
||||
|
||||
def self.call(data = {})
|
||||
new(data).call
|
||||
end
|
||||
|
@ -180,10 +190,6 @@ class ProblemCheck
|
|||
|
||||
private
|
||||
|
||||
def tracker(target = NO_TARGET)
|
||||
ProblemCheckTracker[identifier, target]
|
||||
end
|
||||
|
||||
def targets
|
||||
[NO_TARGET]
|
||||
end
|
||||
|
|
|
@ -31,6 +31,17 @@ RSpec.describe Jobs::RunProblemChecks do
|
|||
ProblemCheck.send(:remove_const, "DisabledCheck")
|
||||
end
|
||||
|
||||
context "when a tracker hasn't been created yet" do
|
||||
it "still schedules checks" do
|
||||
expect_enqueued_with(
|
||||
job: :run_problem_check,
|
||||
args: {
|
||||
check_identifier: "scheduled_check",
|
||||
},
|
||||
) { described_class.new.execute([]) }
|
||||
end
|
||||
end
|
||||
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue