mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-05 03:41:24 +08:00
Scheduled problem checks with multiple targets are not honouring the `run_every` configuration. For checks with multiple targets, all targets are checked in a single instance of the problem check. However, we have one problem check tracker per target. This mismatch results in the `#ready_to_run?` method always creating a tracker with no target when being checked. This commit fixes that by: **Expect checks to operate on a single target.** This change makes it so that instances of a `ProblemCheck` class are initialized with a target. So instead of 1-N we now have an N-N relationship between checks and trackers. Each instance can access their `target` through an attribute of the same name. This also means problem checks are back to returning a singular `Problem` or `nil`, instead of `[Problem]` or `[]`. For scheduled checks, this means that `ScheduleProblemChecks` now enqueues `N` jobs (where `N` is the number of targets) per check instead of `1` job per check. **Update existing targeted checks to operate on a single target.** This is essentially just removing the loop inside the check.
37 lines
976 B
Ruby
37 lines
976 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class RetrySignal < Exception
|
|
end
|
|
|
|
# This job runs a singular scheduled admin check. It is scheduled by
|
|
# the ProblemChecks (plural) scheduled job.
|
|
class RunProblemCheck < ::Jobs::Base
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
retry_count = args[:retry_count].to_i
|
|
identifier = args[:check_identifier].to_sym
|
|
target = args[:target].to_s
|
|
|
|
return if target.blank?
|
|
|
|
check = ProblemCheck[identifier]
|
|
|
|
check
|
|
.new(target)
|
|
.run { |problem| raise RetrySignal if problem.present? && retry_count < check.max_retries }
|
|
rescue RetrySignal
|
|
Jobs.enqueue_in(
|
|
check.retry_after,
|
|
:run_problem_check,
|
|
args.merge(retry_count: retry_count + 1),
|
|
)
|
|
rescue StandardError => err
|
|
Discourse.warn_exception(
|
|
err,
|
|
message: "A scheduled admin dashboard problem check (#{identifier}) errored.",
|
|
)
|
|
end
|
|
end
|
|
end
|