Class: Searchkick::ReindexQueue
- Inherits:
-
Object
- Object
- Searchkick::ReindexQueue
- Defined in:
- lib/searchkick/reindex_queue.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #clear ⇒ Object
-
#initialize(name) ⇒ ReindexQueue
constructor
A new instance of ReindexQueue.
- #length ⇒ Object
- #push(record_id) ⇒ Object
-
#reserve(limit: 1000) ⇒ Object
TODO use reliable queuing.
Constructor Details
#initialize(name) ⇒ ReindexQueue
Returns a new instance of ReindexQueue.
5 6 7 8 9 |
# File 'lib/searchkick/reindex_queue.rb', line 5 def initialize(name) @name = name raise Searchkick::Error, "Searchkick.redis not set" unless Searchkick.redis end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/searchkick/reindex_queue.rb', line 3 def name @name end |
Instance Method Details
#clear ⇒ Object
24 25 26 |
# File 'lib/searchkick/reindex_queue.rb', line 24 def clear Searchkick.with_redis { |r| r.del(redis_key) } end |
#length ⇒ Object
28 29 30 |
# File 'lib/searchkick/reindex_queue.rb', line 28 def length Searchkick.with_redis { |r| r.llen(redis_key) } end |
#push(record_id) ⇒ Object
11 12 13 |
# File 'lib/searchkick/reindex_queue.rb', line 11 def push(record_id) Searchkick.with_redis { |r| r.lpush(redis_key, record_id) } end |
#reserve(limit: 1000) ⇒ Object
TODO use reliable queuing
16 17 18 19 20 21 22 |
# File 'lib/searchkick/reindex_queue.rb', line 16 def reserve(limit: 1000) record_ids = Set.new while record_ids.size < limit && (record_id = Searchkick.with_redis { |r| r.rpop(redis_key) }) record_ids << record_id end record_ids.to_a end |