summaryrefslogtreecommitdiff
path: root/app/workers/gitlab_usage_ping_worker.rb
blob: 0a55aab63fd8a5bafbb2934068aa3de261e332a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class GitlabUsagePingWorker
  LEASE_TIMEOUT = 86400

  include Sidekiq::Worker
  include CronjobQueue

  def perform
    # Multiple Sidekiq workers could run this. We should only do this at most once a day.
    return unless try_obtain_lease

    SubmitUsagePingService.new.execute
  end

  private

  def try_obtain_lease
    Gitlab::ExclusiveLease.new('gitlab_usage_ping_worker:ping', timeout: LEASE_TIMEOUT).try_obtain
  end
end