Class: HasHelpers::ReindexQueue
- Inherits:
-
Object
- Object
- HasHelpers::ReindexQueue
- Defined in:
- app/models/has_helpers/reindex_queue.rb
Class Method Summary collapse
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(index_name) ⇒ ReindexQueue
constructor
A new instance of ReindexQueue.
- #length ⇒ Object
- #push(record_id, key = nil, routing_key: nil) ⇒ Object
- #reserve(limit: 1000) ⇒ Object
Constructor Details
#initialize(index_name) ⇒ ReindexQueue
Returns a new instance of ReindexQueue.
9 10 11 |
# File 'app/models/has_helpers/reindex_queue.rb', line 9 def initialize(index_name) @index_name = index_name end |
Class Method Details
.redis ⇒ Object
5 6 7 |
# File 'app/models/has_helpers/reindex_queue.rb', line 5 def self.redis RedisConf.current end |
Instance Method Details
#clear ⇒ Object
29 30 31 |
# File 'app/models/has_helpers/reindex_queue.rb', line 29 def clear self.class.redis.with { |redis| redis.del(redis_key) } end |
#length ⇒ Object
33 34 35 |
# File 'app/models/has_helpers/reindex_queue.rb', line 33 def length self.class.redis.with { |redis| redis.llen(redis_key) } end |
#push(record_id, key = nil, routing_key: nil) ⇒ Object
13 14 15 16 |
# File 'app/models/has_helpers/reindex_queue.rb', line 13 def push(record_id, key = nil, routing_key: nil) data = { record_id: record_id, key: key, routing_key: routing_key }.to_json self.class.redis.with { |redis| redis.lpush(redis_key, data) } end |
#reserve(limit: 1000) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/has_helpers/reindex_queue.rb', line 18 def reserve(limit: 1000) reserved_records = [] self.class.redis.with do |redis| limit.times do data = redis.rpop(redis_key) reserved_records << JSON.parse(data, symbolize_names: true) if data end end reserved_records end |