Class: ThinkingSphinx::Deltas::Job
- Inherits:
-
Delayed::Backend::ActiveRecord::Job
- Object
- ActiveRecord::Base
- Delayed::Backend::ActiveRecord::Job
- ThinkingSphinx::Deltas::Job
- Defined in:
- lib/thinking_sphinx/deltas/delayed_delta/job.rb
Overview
A custom job model, subclassed from Delayed::Job. The two things it does differently is that it checks for duplicate tasks before enqueuing them, and provides the option to remove all Delayed Delta jobs from the queue.
As such, this class should not be used for any other tasks.
Class Method Summary collapse
-
.cancel_thinking_sphinx_jobs ⇒ Object
Remove all Thinking Sphinx/Delayed Delta jobs from the queue.
-
.enqueue(object, priority = 0) ⇒ Object
Adds a job to the queue, if it doesn’t already exist.
-
.inspect ⇒ Object
This is to stop ActiveRecord complaining about a missing database when running specs (otherwise printing failure messages raises confusing stack traces).
Class Method Details
.cancel_thinking_sphinx_jobs ⇒ Object
Remove all Thinking Sphinx/Delayed Delta jobs from the queue. If the delayed_jobs table does not exist, this method will do nothing.
36 37 38 39 40 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/job.rb', line 36 def self.cancel_thinking_sphinx_jobs if connection.tables.include?("delayed_jobs") delete_all("handler LIKE '--- !ruby/object:ThinkingSphinx::Deltas::%'") end end |
.enqueue(object, priority = 0) ⇒ Object
Adds a job to the queue, if it doesn’t already exist. This is to ensure multiple indexing requests for the same delta index don’t get added, as the index only needs to be processed once.
Because indexing jobs are all the same object, with a single instance variable (the index name), they all get serialised to the same YAML value.
29 30 31 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/job.rb', line 29 def self.enqueue(object, priority = 0) ::Delayed::Job.enqueue(object, :priority => priority) unless duplicates_exist(object) end |
.inspect ⇒ Object
This is to stop ActiveRecord complaining about a missing database when running specs (otherwise printing failure messages raises confusing stack traces).
46 47 48 |
# File 'lib/thinking_sphinx/deltas/delayed_delta/job.rb', line 46 def self.inspect "Job" end |