Class: Searchkick::ReindexQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/searchkick/reindex_queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ReindexQueue

Returns a new instance of ReindexQueue.

Raises:


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

#nameObject (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

#clearObject


24
25
26
# File 'lib/searchkick/reindex_queue.rb', line 24

def clear
  Searchkick.with_redis { |r| r.del(redis_key) }
end

#lengthObject


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