Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab_usage_ping_worker.rb « workers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a696c6e746a427cf189875d88971e430dc2d0d07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# frozen_string_literal: true

class GitlabUsagePingWorker # rubocop:disable Scalability/IdempotentWorker
  LEASE_KEY = 'gitlab_usage_ping_worker:ping'
  LEASE_TIMEOUT = 86400

  include ApplicationWorker
  include CronjobQueue # rubocop:disable Scalability/CronWorkerContext
  include Gitlab::ExclusiveLeaseHelpers

  feature_category :collection
  sidekiq_options retry: 3, dead: false
  sidekiq_retry_in { |count| (count + 1) * 8.hours.to_i }

  def perform
    # Multiple Sidekiq workers could run this. We should only do this at most once a day.
    in_lock(LEASE_KEY, ttl: LEASE_TIMEOUT) do
      # Splay the request over a minute to avoid thundering herd problems.
      sleep(rand(0.0..60.0).round(3))

      SubmitUsagePingService.new.execute
    end
  end
end