Cache the last usage data to avoid unicorn timeouts

This commit is contained in:
Stan Hu 2016-10-04 15:32:02 -07:00 committed by Rémy Coutable
parent c53afeda0c
commit bca368990a
2 changed files with 5 additions and 5 deletions

View File

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

View File

@ -3,16 +3,16 @@ module Gitlab
include Gitlab::CurrentSettings include Gitlab::CurrentSettings
class << self class << self
def data def data(force_refresh = false)
Rails.cache.fetch('usage_data', expires_in: 1.hour) { uncached_data } Rails.cache.fetch('usage_data', force: force_refresh) { 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 def to_json(force_refresh = false)
data.to_json data(force_refresh).to_json
end end
def system_usage_data def system_usage_data