mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:03:43 +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
|
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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user