Sha256: 56090b2d7b5e3dede28f3b9d6c5b1684bf90e85bde7b9899950167cbfa21716b
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
# 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 ThinkingSphinx::Deltas::Job < Delayed::Job # 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. # # @param [Object] object The job, which must respond to the #perform method. # @param [Integer] priority (0) # def self.enqueue(object, priority = 0) Delayed::Job.enqueue(object, priority) unless duplicates_exist(object) end # Remove all Thinking Sphinx/Delayed Delta jobs from the queue. If the # delayed_jobs table does not exist, this method will do nothing. # def self.cancel_thinking_sphinx_jobs if connection.tables.include?("delayed_jobs") delete_all("handler LIKE '--- !ruby/object:ThinkingSphinx::Deltas::%'") end end # This is to stop ActiveRecord complaining about a missing database when # running specs (otherwise printing failure messages raises confusing stack # traces). # def self.inspect "Job" end private # Checks whether a given job already exists in the queue. # # @param [Object] object The job # @return [Boolean] True if a duplicate of the job already exists in the queue # def self.duplicates_exist(object) count( :conditions => { :handler => object.to_yaml, :locked_at => nil } ) > 0 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ts-delayed-delta-1.0.0 | lib/thinking_sphinx/deltas/delayed_delta/job.rb |