Commit f30a46b4 authored by Stan Hu's avatar Stan Hu Committed by Rémy Coutable

Used named parameter for refreshing usage data

parent bca36899
...@@ -15,7 +15,7 @@ class GitlabUsagePingWorker ...@@ -15,7 +15,7 @@ class GitlabUsagePingWorker
begin begin
HTTParty.post(url, HTTParty.post(url,
body: Gitlab::UsageData.to_json(true), body: Gitlab::UsageData.to_json(force_refresh: true),
headers: { 'Content-type' => 'application/json' } headers: { 'Content-type' => 'application/json' }
) )
rescue HTTParty::Error => e rescue HTTParty::Error => e
......
...@@ -3,16 +3,16 @@ module Gitlab ...@@ -3,16 +3,16 @@ module Gitlab
include Gitlab::CurrentSettings include Gitlab::CurrentSettings
class << self class << self
def data(force_refresh = false) def data(force_refresh: false)
Rails.cache.fetch('usage_data', force: force_refresh) { uncached_data } Rails.cache.fetch('usage_data', force: force_refresh, expires_in: 2.weeks) { uncached_data }
end end
def uncached_data def uncached_data
license_usage_data.merge(system_usage_data) license_usage_data.merge(system_usage_data)
end end
def to_json(force_refresh = false) def to_json(force_refresh: false)
data(force_refresh).to_json data(force_refresh: force_refresh).to_json
end end
def system_usage_data def system_usage_data
......
...@@ -8,6 +8,7 @@ describe GitlabUsagePingWorker do ...@@ -8,6 +8,7 @@ describe GitlabUsagePingWorker do
stub_request(:post, "https://version.gitlab.com/usage_data"). stub_request(:post, "https://version.gitlab.com/usage_data").
to_return(status: 200, body: '', headers: {}) 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).to receive(:try_obtain_lease).and_return(true)
expect(subject.perform.response.code.to_i).to eq(200) expect(subject.perform.response.code.to_i).to eq(200)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment