Class: ThinkingSphinx::Deltas::SidekiqDelta
- Inherits:
-
DefaultDelta
- Object
- DefaultDelta
- ThinkingSphinx::Deltas::SidekiqDelta
- Defined in:
- lib/thinking_sphinx/deltas/sidekiq_delta.rb
Constant Summary collapse
- JOB_TYPES =
[]
- JOB_PREFIX =
'ts-delta'
Class Method Summary collapse
-
.clear! ⇒ Object
Clear both the resque queues and any other state maintained in redis.
-
.clear_thinking_sphinx_queues ⇒ Object
LTRIM + LPOP deletes all items from the Resque queue without loading it into client memory (unlike Resque.dequeue).
-
.lock(index_name) ⇒ Object
Use simplistic locking.
- .locked?(index_name) ⇒ Boolean
- .unlock(index_name) ⇒ Object
Instance Method Summary collapse
Class Method Details
.clear! ⇒ Object
Clear both the resque queues and any other state maintained in redis
22 23 24 25 26 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 22 def self.clear! self.clear_thinking_sphinx_queues FlagAsDeletedSet.clear_all! end |
.clear_thinking_sphinx_queues ⇒ Object
LTRIM + LPOP deletes all items from the Resque queue without loading it into client memory (unlike Resque.dequeue). WARNING: This will clear ALL jobs in any queue used by a ResqueDelta job. If you’re sharing a queue with other jobs they’ll be deleted!
12 13 14 15 16 17 18 19 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 12 def self.clear_thinking_sphinx_queues JOB_TYPES.collect { |job| job.['queue'] }.uniq.each do |queue| Sidekiq.redis { |redis| redis.srem "queues", queue } Sidekiq.redis { |redis| redis.del "queue:#{queue}" } end end |
.lock(index_name) ⇒ Object
Use simplistic locking. We’re assuming that the user won’t run more than one ‘rake ts:si` or `rake ts:in` task at a time.
30 31 32 33 34 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 30 def self.lock(index_name) Sidekiq.redis {|redis| redis.set("#{JOB_PREFIX}:index:#{index_name}:locked", 'true') } end |
.locked?(index_name) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 42 def self.locked?(index_name) Sidekiq.redis {|redis| redis.get("#{JOB_PREFIX}:index:#{index_name}:locked") == 'true' } end |
.unlock(index_name) ⇒ Object
36 37 38 39 40 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 36 def self.unlock(index_name) Sidekiq.redis {|redis| redis.del("#{JOB_PREFIX}:index:#{index_name}:locked") } end |
Instance Method Details
#delete(index, instance) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 48 def delete(index, instance) return if self.class.locked?(index.reference) ThinkingSphinx::Deltas::SidekiqDelta::FlagAsDeletedJob.perform_async( index.name, index.document_id_for_key(instance.id) ) end |
#index(index) ⇒ Object
56 57 58 59 60 |
# File 'lib/thinking_sphinx/deltas/sidekiq_delta.rb', line 56 def index(index) return if self.class.locked?(index.reference) ThinkingSphinx::Deltas::SidekiqDelta::DeltaJob.perform_async(index.name) end |