Class: ThinkingSphinx::Deltas::DelayedDelta

Inherits:
DefaultDelta
  • Object
show all
Includes:
Binary, SphinxQL
Defined in:
lib/thinking_sphinx/deltas/delayed_delta.rb

Overview

Delayed Deltas for Thinking Sphinx, using Delayed Job.

This documentation is aimed at those reading the code. If you’re looking for a guide to Thinking Sphinx and/or deltas, I recommend you start with the Thinking Sphinx site instead - or the README for this library at the very least.

See Also:

Author:

  • Patrick Allan

Defined Under Namespace

Modules: Binary, SphinxQL

Class Method Summary collapse

Methods included from SphinxQL

#delete, #index

Methods included from Binary

#index

Class Method Details

.cancel_jobsObject



17
18
19
20
21
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 17

def self.cancel_jobs
  Delayed::Job.delete_all(
    "handler LIKE '--- !ruby/object:ThinkingSphinx::Deltas::%'"
  )
end

.enqueue_unless_duplicates(object) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 23

def self.enqueue_unless_duplicates(object)
  if Delayed::Job.respond_to?(:where)
    return if Delayed::Job.where(
      :handler => object.to_yaml, :locked_at => nil
    ).count > 0
  else
    return if Delayed::Job.count(
      :conditions => {:handler => object.to_yaml, :locked_at => nil}
    ) > 0
  end

  Delayed::Job.enqueue object, priority_option
end

.priorityObject



46
47
48
49
50
51
52
53
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 46

def self.priority
  configuration = ThinkingSphinx::Configuration.instance
  if configuration.respond_to? :delayed_job_priority
    configuration.delayed_job_priority
  else
    configuration.settings['delayed_job_priority'] || 0
  end
end

.priority_optionObject



37
38
39
40
41
42
43
44
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 37

def self.priority_option
  if Gem.loaded_specs['delayed_job'].version.to_s.match(/^2\.0\./)
    # Fallback for compatibility with old release 2.0.x of DJ
    priority
  else
    {:priority => priority}
  end
end