Skip to content

Instantly share code, notes, and snippets.

@pat
Last active August 21, 2019 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pat/53dbe982a2b311f5f7294809109419d2 to your computer and use it in GitHub Desktop.
Save pat/53dbe982a2b311f5f7294809109419d2 to your computer and use it in GitHub Desktop.
Thinking Sphinx parallel processing of real-time indices.
# This will process each real-time index in parallel (using separate
# processes, up to the number of CPUs available).
#
# You will also need the 'parallel' gem, and what is currently the
# edge release of Thinking Sphinx (until there's been a release after
# v4.3.2).
#
# This could all go in an initialiser, or put the class wherever you
# like, and the assignment in the initialiser.
class ParallelProcessor < ThinkingSphinx::RealTime::Processor
def call(&block)
Parallel.map(indices) do |index|
puts "Populating index #{index.name}"
ThinkingSphinx::RealTime.populator.populate index
puts "Populated index #{index.name}"
block.call
end
end
end
ThinkingSphinx::RealTime.processor = ParallelProcessor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment