Class: Gitlab::UsageCounters::Common

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/usage_counters/common.rb

Direct Known Subclasses

PodLogs

Class Method Summary collapse

Class Method Details

.base_keyObject

Raises:

  • (NotImplementedError)

24
25
26
# File 'lib/gitlab/usage_counters/common.rb', line 24

def base_key
  raise NotImplementedError
end

.increment(project_id) ⇒ Object


7
8
9
# File 'lib/gitlab/usage_counters/common.rb', line 7

def increment(project_id)
  Gitlab::Redis::SharedState.with { |redis| redis.hincrby(base_key, project_id, 1) }
end

.usage_totalsObject


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/usage_counters/common.rb', line 11

def usage_totals
  Gitlab::Redis::SharedState.with do |redis|
    total_sum = 0

    totals = redis.hgetall(base_key).each_with_object({}) do |(project_id, count), result|
      total_sum += result[project_id.to_i] = count.to_i
    end

    totals[:total] = total_sum
    totals
  end
end