Used named parameter for refreshing usage data

This commit is contained in:
Stan Hu 2016-10-19 14:29:01 -07:00 committed by Rémy Coutable
parent bca368990a
commit f30a46b401
3 changed files with 6 additions and 5 deletions

View file

@ -15,7 +15,7 @@ class GitlabUsagePingWorker
begin
HTTParty.post(url,
body: Gitlab::UsageData.to_json(true),
body: Gitlab::UsageData.to_json(force_refresh: true),
headers: { 'Content-type' => 'application/json' }
)
rescue HTTParty::Error => e

View file

@ -3,16 +3,16 @@ module Gitlab
include Gitlab::CurrentSettings
class << self
def data(force_refresh = false)
Rails.cache.fetch('usage_data', force: force_refresh) { uncached_data }
def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
end
def uncached_data
license_usage_data.merge(system_usage_data)
end
def to_json(force_refresh = false)
data(force_refresh).to_json
def to_json(force_refresh: false)
data(force_refresh: force_refresh).to_json
end
def system_usage_data

View file

@ -8,6 +8,7 @@ describe GitlabUsagePingWorker do
stub_request(:post, "https://version.gitlab.com/usage_data").
to_return(status: 200, body: '', headers: {})
expect(Gitlab::UsageData).to receive(:to_json).with({ force_refresh: true }).and_call_original
expect(subject).to receive(:try_obtain_lease).and_return(true)
expect(subject.perform.response.code.to_i).to eq(200)