2023-11-02 21:05:29 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2023-11-05 19:57:02 -05:00
|
|
|
class RetrySignal < Exception
|
|
|
|
end
|
|
|
|
|
2023-11-02 21:05:29 -04:00
|
|
|
# This job runs a singular scheduled admin check. It is scheduled by
|
|
|
|
# the ProblemChecks (plural) scheduled job.
|
2024-03-06 23:26:58 -05:00
|
|
|
class RunProblemCheck < ::Jobs::Base
|
2023-11-02 21:05:29 -04:00
|
|
|
sidekiq_options retry: false
|
|
|
|
|
|
|
|
def execute(args)
|
2023-11-05 19:57:02 -05:00
|
|
|
retry_count = args[:retry_count].to_i
|
|
|
|
identifier = args[:check_identifier].to_sym
|
|
|
|
|
2024-03-06 23:26:58 -05:00
|
|
|
check = ProblemCheck[identifier]
|
2023-11-02 21:05:29 -04:00
|
|
|
|
2024-02-22 22:20:32 -05:00
|
|
|
problems = check.call
|
|
|
|
raise RetrySignal if problems.present? && retry_count < check.max_retries
|
|
|
|
|
2024-02-26 22:17:39 -05:00
|
|
|
if problems.present?
|
|
|
|
problems.each { |problem| AdminDashboardData.add_found_scheduled_check_problem(problem) }
|
|
|
|
ProblemCheckTracker[identifier].problem!(next_run_at: check.perform_every.from_now)
|
|
|
|
else
|
|
|
|
ProblemCheckTracker[identifier].no_problem!(next_run_at: check.perform_every.from_now)
|
|
|
|
end
|
2023-11-05 19:57:02 -05:00
|
|
|
rescue RetrySignal
|
|
|
|
Jobs.enqueue_in(
|
2024-02-22 22:20:32 -05:00
|
|
|
check.retry_after,
|
2024-03-06 23:26:58 -05:00
|
|
|
:run_problem_check,
|
2023-11-05 19:57:02 -05:00
|
|
|
args.merge(retry_count: retry_count + 1).stringify_keys,
|
|
|
|
)
|
2024-02-22 22:20:32 -05:00
|
|
|
rescue StandardError => err
|
|
|
|
Discourse.warn_exception(
|
|
|
|
err,
|
|
|
|
message: "A scheduled admin dashboard problem check (#{identifier}) errored.",
|
|
|
|
)
|
2023-11-02 21:05:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|