diff options
author | Sean McGivern <sean@gitlab.com> | 2017-04-05 15:19:59 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-14 16:20:55 +0300 |
commit | ebd5e9b4549ebc80155a5a8f139efdb40b6f8b12 (patch) | |
tree | 84d7f3066f0dbf7022bc0ec58cb3ab235006715a /app/workers | |
parent | c3bb21ff800699bed829a30c75fa81fd0d4dab8d (diff) |
Port 'Add EE usage ping' to CE
CE port of https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/557
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/gitlab_usage_ping_worker.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/app/workers/gitlab_usage_ping_worker.rb b/app/workers/gitlab_usage_ping_worker.rb new file mode 100644 index 00000000000..2e039b7f3c5 --- /dev/null +++ b/app/workers/gitlab_usage_ping_worker.rb @@ -0,0 +1,40 @@ +class GitlabUsagePingWorker + LEASE_TIMEOUT = 86400 + + include Sidekiq::Worker + include HTTParty + + # This is not guaranteed to succeed, so don't retry on failure + sidekiq_options queue: :default, retry: false + + 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, + body: data.to_json, + 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 data + usage_data = { version: Gitlab::VERSION, + active_user_count: User.active.acount } + + usage_data + end + + def url + 'https://version.gitlab.com/usage_data' + end +end |