2023-11-03 09:05:29 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
2023-11-06 08:57:02 +08:00
|
|
|
class RetrySignal < Exception
|
|
|
|
end
|
|
|
|
|
2023-11-03 09:05:29 +08:00
|
|
|
# This job runs a singular scheduled admin check. It is scheduled by
|
|
|
|
# the ProblemChecks (plural) scheduled job.
|
|
|
|
class ProblemCheck < ::Jobs::Base
|
|
|
|
sidekiq_options retry: false
|
|
|
|
|
|
|
|
def execute(args)
|
2023-11-06 08:57:02 +08:00
|
|
|
retry_count = args[:retry_count].to_i
|
|
|
|
identifier = args[:check_identifier].to_sym
|
|
|
|
|
|
|
|
check = AdminDashboardData.problem_scheduled_check_klasses[identifier]
|
2023-11-03 09:05:29 +08:00
|
|
|
|
2023-11-06 08:57:02 +08:00
|
|
|
AdminDashboardData.execute_scheduled_check(identifier) do |problems|
|
|
|
|
raise RetrySignal if retry_count < check.max_retries
|
|
|
|
end
|
|
|
|
rescue RetrySignal
|
|
|
|
Jobs.enqueue_in(
|
|
|
|
check.retry_wait,
|
|
|
|
:problem_check,
|
|
|
|
args.merge(retry_count: retry_count + 1).stringify_keys,
|
|
|
|
)
|
2023-11-03 09:05:29 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|