mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 23:53:48 +08:00
c3708c4276
We updated scheduled admin checks to run concurrently in their own jobs. The main reason for this was so that we can implement re-check functionality for especially flaky checks (e.g. group e-mail credentials check.) This works in the following way: 1. The check declares its retry policy using class methods. 2. A block can be yielded to if there are problems, but before they are committed to Redis. 3. The job uses this block to either a) schedule a retry if there are any remaining or b) do nothing and let the check commit.
30 lines
797 B
Ruby
30 lines
797 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 ProblemCheck < ::Jobs::Base
|
|
sidekiq_options retry: false
|
|
|
|
def execute(args)
|
|
retry_count = args[:retry_count].to_i
|
|
identifier = args[:check_identifier].to_sym
|
|
|
|
check = AdminDashboardData.problem_scheduled_check_klasses[identifier]
|
|
|
|
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,
|
|
)
|
|
end
|
|
end
|
|
end
|