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 (?) AND locked_at IS NULL AND locked_by IS NULL AND failed_at IS NULL", "--- !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, job_options
end

.job_option(setting, default = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/thinking_sphinx/deltas/delayed_delta.rb', line 50

def self.job_option(setting, default = nil)
  configuration = ThinkingSphinx::Configuration.instance
  if configuration.respond_to? setting
    configuration.send(setting)
  elsif configuration.respond_to? :settings
    configuration.settings[setting.to_s] || default
  else
    default
  end
end

.job_optionsObject



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

def self.job_options
  if Gem.loaded_specs['delayed_job'].version.to_s.match(/^2\.0\./)
    # Fallback for compatibility with old release 2.0.x of DJ
    # Only priority option is supported for these versions
    ThinkingSphinx::Configuration.instance.delayed_job_priority || 0
  else
    {
      :priority => job_option(:delayed_job_priority, 0),
      :queue    => job_option(:delayed_job_queue)
    }
  end
end