Skip to content
Snippets Groups Projects
Commit e8f59261 authored by Valery Sizov's avatar Valery Sizov
Browse files

User redis connection pool in Geo

parent 0e46d6f6
Branches andrey-remove-group-caching
No related tags found
No related merge requests found
Pipeline #12834678 failed
Loading
Loading
@@ -5,11 +5,14 @@ class UpdateQueue
NAMESPACE = 'geo:gitlab'
 
def initialize(queue)
@queue = queue
@queue = "#{NAMESPACE}:#{queue}"
end
 
def store(data)
redis.rpush(@queue, data.to_json)
Gitlab::Redis.with do |redis|
redis.rpush(@queue, data.to_json)
end
expire_queue_size!
end
 
Loading
Loading
@@ -27,9 +30,11 @@ def fetch_batched_data
projects = []
bsize = batch_size
 
redis.multi do
projects = redis.lrange(@queue, 0, bsize - 1)
redis.ltrim(@queue, bsize, -1)
Gitlab::Redis.with do |redis|
redis.multi do
projects = redis.lrange(@queue, 0, bsize - 1)
redis.ltrim(@queue, bsize, -1)
end
end
 
expire_queue_size!
Loading
Loading
@@ -37,12 +42,15 @@ def fetch_batched_data
end
 
def store_batched_data(projects)
redis.pipelined do
projects.reverse_each do |project|
# enqueue again to the head of the queue
redis.lpush(@queue, project.to_json)
Gitlab::Redis.with do |redis|
redis.pipelined do
projects.reverse_each do |project|
# enqueue again to the head of the queue
redis.lpush(@queue, project.to_json)
end
end
end
expire_queue_size!
end
 
Loading
Loading
@@ -59,17 +67,23 @@ def empty?
end
 
def empty!
redis.del(@queue)
Gitlab::Redis.with do |redis|
redis.del(@queue)
end
end
 
protected
 
def fetch(start, stop)
deserialize(redis.lrange(@queue, start, stop))
Gitlab::Redis.with do |redis|
deserialize(redis.lrange(@queue, start, stop))
end
end
 
def fetch_queue_size
redis.llen(@queue)
Gitlab::Redis.with do |redis|
redis.llen(@queue)
end
end
 
def expire_queue_size!
Loading
Loading
@@ -80,26 +94,6 @@ def deserialize(data)
data.map! { |item| JSON.parse(item) } unless data.empty?
data
end
def redis
self.class.redis
end
def self.redis_connection
redis_config_file = Rails.root.join('config', 'resque.yml')
redis_url_string = if File.exists?(redis_config_file)
YAML.load_file(redis_config_file)[Rails.env]
else
'redis://localhost:6379'
end
::Redis::Namespace.new(NAMESPACE, redis: ::Redis.new(url: redis_url_string))
end
def self.redis
@redis ||= redis_connection
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment