2017-04-05 08:19:59 -04:00
|
|
|
class GitlabUsagePingWorker
|
|
|
|
LEASE_TIMEOUT = 86400
|
|
|
|
|
|
|
|
include Sidekiq::Worker
|
2017-04-06 15:13:52 -04:00
|
|
|
include CronjobQueue
|
2017-04-05 08:19:59 -04:00
|
|
|
include HTTParty
|
|
|
|
|
|
|
|
def perform
|
|
|
|
return unless current_application_settings.usage_ping_enabled
|
|
|
|
|
|
|
|
# Multiple Sidekiq workers could run this. We should only do this at most once a day.
|
|
|
|
return unless try_obtain_lease
|
|
|
|
|
|
|
|
begin
|
|
|
|
HTTParty.post(url,
|
2016-10-19 17:29:01 -04:00
|
|
|
body: Gitlab::UsageData.to_json(force_refresh: true),
|
2017-04-05 08:19:59 -04:00
|
|
|
headers: { 'Content-type' => 'application/json' }
|
|
|
|
)
|
|
|
|
rescue HTTParty::Error => e
|
|
|
|
Rails.logger.info "Unable to contact GitLab, Inc.: #{e}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def try_obtain_lease
|
|
|
|
Gitlab::ExclusiveLease.new('gitlab_usage_ping_worker:ping', timeout: LEASE_TIMEOUT).try_obtain
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
'https://version.gitlab.com/usage_data'
|
|
|
|
end
|
|
|
|
end
|