summaryrefslogtreecommitdiff
path: root/lib/gitlab/usage_data_counters
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2019-07-17 23:45:35 +0000
committerNick Thomas <nick@gitlab.com>2019-07-17 23:45:35 +0000
commitbcd2458076512ad80c6e470d9434618f27dfec3c (patch)
tree92081015f8202b37abb3e6c79808e84ce0dccbe9 /lib/gitlab/usage_data_counters
parentf74bd44d2a9171c51ec7c9a622d7628044791d9e (diff)
downloadgitlab-ce-bcd2458076512ad80c6e470d9434618f27dfec3c.tar.gz
Refactor RedisCounter and WebIdeCommitsCounter
This MR refactor RedisCounter and WebIdeCommitsCounter to be reused by other components.
Diffstat (limited to 'lib/gitlab/usage_data_counters')
-rw-r--r--lib/gitlab/usage_data_counters/redis_counter.rb8
-rw-r--r--lib/gitlab/usage_data_counters/web_ide_commits_counter.rb13
-rw-r--r--lib/gitlab/usage_data_counters/web_ide_counter.rb21
3 files changed, 23 insertions, 19 deletions
diff --git a/lib/gitlab/usage_data_counters/redis_counter.rb b/lib/gitlab/usage_data_counters/redis_counter.rb
index 123b8e1bef1..d10871f704c 100644
--- a/lib/gitlab/usage_data_counters/redis_counter.rb
+++ b/lib/gitlab/usage_data_counters/redis_counter.rb
@@ -3,17 +3,13 @@
module Gitlab
module UsageDataCounters
module RedisCounter
- def increment
+ def increment(redis_counter_key)
Gitlab::Redis::SharedState.with { |redis| redis.incr(redis_counter_key) }
end
- def total_count
+ def total_count(redis_counter_key)
Gitlab::Redis::SharedState.with { |redis| redis.get(redis_counter_key).to_i }
end
-
- def redis_counter_key
- raise NotImplementedError
- end
end
end
end
diff --git a/lib/gitlab/usage_data_counters/web_ide_commits_counter.rb b/lib/gitlab/usage_data_counters/web_ide_commits_counter.rb
deleted file mode 100644
index 62236fa07a3..00000000000
--- a/lib/gitlab/usage_data_counters/web_ide_commits_counter.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- module UsageDataCounters
- class WebIdeCommitsCounter
- extend RedisCounter
-
- def self.redis_counter_key
- 'WEB_IDE_COMMITS_COUNT'
- end
- end
- end
-end
diff --git a/lib/gitlab/usage_data_counters/web_ide_counter.rb b/lib/gitlab/usage_data_counters/web_ide_counter.rb
new file mode 100644
index 00000000000..6fbffb94c58
--- /dev/null
+++ b/lib/gitlab/usage_data_counters/web_ide_counter.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module UsageDataCounters
+ class WebIdeCounter
+ extend RedisCounter
+
+ COMMITS_COUNT_KEY = 'WEB_IDE_COMMITS_COUNT'
+
+ class << self
+ def increment_commits_count
+ increment(COMMITS_COUNT_KEY)
+ end
+
+ def total_commits_count
+ total_count(COMMITS_COUNT_KEY)
+ end
+ end
+ end
+ end
+end