Commit 357090bb authored by Gabriel Mazetto's avatar Gabriel Mazetto

we should reuse same redis connection for UpdateQueue

parent 413cb0af
...@@ -5,12 +5,8 @@ module Gitlab ...@@ -5,12 +5,8 @@ module Gitlab
NAMESPACE = 'geo:gitlab' NAMESPACE = 'geo:gitlab'
QUEUE = 'updated_projects' QUEUE = 'updated_projects'
def initialize
@redis = redis_connection
end
def store(data) def store(data)
@redis.rpush(QUEUE, data.to_json) redis.rpush(QUEUE, data.to_json)
expire_queue_size! expire_queue_size!
end end
...@@ -28,9 +24,9 @@ module Gitlab ...@@ -28,9 +24,9 @@ module Gitlab
projects = [] projects = []
bsize = batch_size bsize = batch_size
@redis.multi do redis.multi do
projects = @redis.lrange(QUEUE, 0, bsize - 1) projects = redis.lrange(QUEUE, 0, bsize - 1)
@redis.ltrim(QUEUE, bsize, -1) redis.ltrim(QUEUE, bsize, -1)
end end
expire_queue_size! expire_queue_size!
...@@ -38,10 +34,10 @@ module Gitlab ...@@ -38,10 +34,10 @@ module Gitlab
end end
def store_batched_data(projects) def store_batched_data(projects)
@redis.pipelined do redis.pipelined do
projects.reverse_each do |project| projects.reverse_each do |project|
# enqueue again to the head of the queue # enqueue again to the head of the queue
@redis.lpush(QUEUE, project.to_json) redis.lpush(QUEUE, project.to_json)
end end
end end
expire_queue_size! expire_queue_size!
...@@ -60,17 +56,17 @@ module Gitlab ...@@ -60,17 +56,17 @@ module Gitlab
end end
def empty! def empty!
@redis.del(QUEUE) redis.del(QUEUE)
end end
protected protected
def fetch(start, stop) def fetch(start, stop)
deserialize(@redis.lrange(QUEUE, start, stop)) deserialize(redis.lrange(QUEUE, start, stop))
end end
def fetch_queue_size def fetch_queue_size
@redis.llen(QUEUE) redis.llen(QUEUE)
end end
def expire_queue_size! def expire_queue_size!
...@@ -82,7 +78,11 @@ module Gitlab ...@@ -82,7 +78,11 @@ module Gitlab
data data
end end
def redis_connection def redis
self.class.redis
end
def self.redis_connection
redis_config_file = Rails.root.join('config', 'resque.yml') redis_config_file = Rails.root.join('config', 'resque.yml')
redis_url_string = if File.exists?(redis_config_file) redis_url_string = if File.exists?(redis_config_file)
...@@ -93,6 +93,10 @@ module Gitlab ...@@ -93,6 +93,10 @@ module Gitlab
Redis::Namespace.new(NAMESPACE, redis: Redis.new(url: redis_url_string)) Redis::Namespace.new(NAMESPACE, redis: Redis.new(url: redis_url_string))
end end
def self.redis
@redis ||= redis_connection
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment