discourse/app/jobs/regular/run_problem_check.rb
Ted Johansson 3137e60653
DEV: Database backed admin notices (#26192)
This PR introduces a basic AdminNotice model to store these notices. Admin notices are categorized by their source/type (currently only notices from problem check.) They also have a priority.
2024-05-23 09:29:08 +08:00

35 lines
915 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
check = ProblemCheck[identifier]
check.run do |problems|
raise RetrySignal if problems.present? && retry_count < check.max_retries
end
rescue RetrySignal
Jobs.enqueue_in(
check.retry_after,
:run_problem_check,
args.merge(retry_count: retry_count + 1).stringify_keys,
)
rescue StandardError => err
Discourse.warn_exception(
err,
message: "A scheduled admin dashboard problem check (#{identifier}) errored.",
)
end
end
end