DEV: Prevents rate limits for new feature checks on multisite (#12053)

This commit is contained in:
Penar Musaraj 2021-02-12 08:52:59 -05:00 committed by GitHub
parent 144584aacb
commit 900d4187ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -6,7 +6,8 @@ module Jobs
every 1.day every 1.day
def execute(args) def execute(args)
DiscourseUpdates.perform_new_feature_check @new_features_json ||= DiscourseUpdates.new_features_payload
DiscourseUpdates.update_new_features(@new_features_json)
end end
end end

View File

@ -115,10 +115,14 @@ module DiscourseUpdates
keys.present? ? keys.map { |k| Discourse.redis.hgetall(k) } : [] keys.present? ? keys.map { |k| Discourse.redis.hgetall(k) } : []
end end
def perform_new_feature_check def new_features_payload
response = Excon.new(new_features_endpoint).request(expects: [200], method: :Get) response = Excon.new(new_features_endpoint).request(expects: [200], method: :Get)
json = JSON.parse(response.body) JSON.parse(response.body)
Discourse.redis.set(new_features_key, response.body) end
def update_new_features(json = nil)
json ||= new_features_payload
Discourse.redis.set(new_features_key, json)
end end
def new_features def new_features

View File

@ -8,4 +8,10 @@ RSpec.describe "Running Sidekiq Jobs in Multisite", type: :multisite do
Jobs::DestroyOldDeletionStubs.new.perform({}) Jobs::DestroyOldDeletionStubs.new.perform({})
end.to_not change { RailsMultisite::ConnectionManagement.current_db } end.to_not change { RailsMultisite::ConnectionManagement.current_db }
end end
it 'CheckNewFeatures should only hit the payload once' do
# otherwise it will get rate-limited by meta
DiscourseUpdates.expects(:new_features_payload).returns("{}").once
Jobs::CheckNewFeatures.new.perform({})
end
end end