Class: ThinkingSphinx::Deltas::SidekiqDelta::DeltaJob

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Worker
Defined in:
lib/thinking_sphinx/deltas/sidekiq_delta/delta_job.rb

Overview

A simple job class that processes a given index.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.around_perform_lock1(*arguments) ⇒ Object

This allows us to have a concurrency safe version of ts-delayed-delta’s duplicates_exist:

github.com/freelancing-god/ts-delayed-delta/blob/master/lib/thinkin g_sphinx/deltas/delayed_delta/job.rb#L47

The name of this method ensures that it runs within around_perform_lock.

We’ve leveraged resque-lock-timeout to ensure that only one DeltaJob is running at a time. Now, this around filter essentially ensures that only one DeltaJob of each index type can sit at the queue at once. If the queue has more than one, lrem will clear the rest off.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/thinking_sphinx/deltas/sidekiq_delta/delta_job.rb', line 34

def self.around_perform_lock1(*arguments)
  # Remove all other instances of this job (with the same args) from the
  # queue. Uses LREM (http://code.google.com/p/redis/wiki/LremCommand) which
  # takes the form: "LREM key count value" and if count == 0 removes all
  # instances of value from the list.
  redis_job_value = {:class => self.to_s, :args => arguments}.to_json

  Sidekiq.redis {|redis|
    redis.lrem("queue:#{@queue}", 0, redis_job_value)
  }

  yield
end

.lock_failed(*arguments) ⇒ Object

Try again later if lock is in use.



17
18
19
# File 'lib/thinking_sphinx/deltas/sidekiq_delta/delta_job.rb', line 17

def self.lock_failed(*arguments)
  self.class.perform_async(*arguments)
end

Instance Method Details

#perform(index) ⇒ Object

Runs Sphinx’s indexer tool to process the index.

Parameters:

  • index (String)

    the name of the Sphinx index



12
13
14
# File 'lib/thinking_sphinx/deltas/sidekiq_delta/delta_job.rb', line 12

def perform(index)
  ThinkingSphinx::Deltas::IndexJob.new(index).perform
end