mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:47:22 +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.
32 lines
982 B
Ruby
32 lines
982 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::ProblemChecks do
|
|
before { Jobs.run_immediately! }
|
|
|
|
after do
|
|
Discourse.redis.flushdb
|
|
AdminDashboardData.reset_problem_checks
|
|
end
|
|
|
|
class TestCheck
|
|
def self.max_retries = 0
|
|
def self.retry_wait = 0.seconds
|
|
end
|
|
|
|
it "starts with a blank slate every time the checks are run to avoid duplicate problems and to clear no longer firing problems" do
|
|
problem_should_fire = true
|
|
AdminDashboardData.reset_problem_checks
|
|
AdminDashboardData.add_scheduled_problem_check(:test_identifier, TestCheck) do
|
|
if problem_should_fire
|
|
problem_should_fire = false
|
|
AdminDashboardData::Problem.new("yuge problem", priority: "high")
|
|
end
|
|
end
|
|
|
|
described_class.new.execute(nil)
|
|
expect(AdminDashboardData.load_found_scheduled_check_problems.count).to eq(1)
|
|
described_class.new.execute(nil)
|
|
expect(AdminDashboardData.load_found_scheduled_check_problems.count).to eq(0)
|
|
end
|
|
end
|