mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 09:42:02 +08:00
DEV: Prevents rate limits for new feature checks on multisite (#12053)
This commit is contained in:
parent
144584aacb
commit
900d4187ef
|
@ -6,7 +6,8 @@ module Jobs
|
|||
every 1.day
|
||||
|
||||
def execute(args)
|
||||
DiscourseUpdates.perform_new_feature_check
|
||||
@new_features_json ||= DiscourseUpdates.new_features_payload
|
||||
DiscourseUpdates.update_new_features(@new_features_json)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -115,10 +115,14 @@ module DiscourseUpdates
|
|||
keys.present? ? keys.map { |k| Discourse.redis.hgetall(k) } : []
|
||||
end
|
||||
|
||||
def perform_new_feature_check
|
||||
def new_features_payload
|
||||
response = Excon.new(new_features_endpoint).request(expects: [200], method: :Get)
|
||||
json = JSON.parse(response.body)
|
||||
Discourse.redis.set(new_features_key, response.body)
|
||||
JSON.parse(response.body)
|
||||
end
|
||||
|
||||
def update_new_features(json = nil)
|
||||
json ||= new_features_payload
|
||||
Discourse.redis.set(new_features_key, json)
|
||||
end
|
||||
|
||||
def new_features
|
||||
|
|
|
@ -8,4 +8,10 @@ RSpec.describe "Running Sidekiq Jobs in Multisite", type: :multisite do
|
|||
Jobs::DestroyOldDeletionStubs.new.perform({})
|
||||
end.to_not change { RailsMultisite::ConnectionManagement.current_db }
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user