class ThinkingSphinx::Deltas::SidekiqDelta::DeltaJob

A simple job class that processes a given index.

Public Class Methods

around_perform_lock1(*arguments) { || ... } click to toggle source

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.

# 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) click to toggle source

Try again later if lock is in use.

# File lib/thinking_sphinx/deltas/sidekiq_delta/delta_job.rb, line 17
def self.lock_failed(*arguments)
  self.class.perform_async(*arguments)
end

Public Instance Methods

perform(index) click to toggle source

Runs Sphinx's indexer tool to process the index.

@param [String] index the name of the Sphinx index

# File lib/thinking_sphinx/deltas/sidekiq_delta/delta_job.rb, line 12
def perform(index)
  ThinkingSphinx::Deltas::IndexJob.new(index).perform
end