Skip to content

Instantly share code, notes, and snippets.

@jamesgolick
Created October 7, 2008 20:29
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 jamesgolick/15370 to your computer and use it in GitHub Desktop.
Save jamesgolick/15370 to your computer and use it in GitHub Desktop.
require 'daemon_controller'
class SearchServer
delegate :start, :to => :controller
attr_reader :controller
def initialize
@controller = DaemonController.new(
:identifier => 'Sphinx search server',
:start_command => 'rake ultrasphinx:daemon:start',
:stop_command => 'rake ultrasphinx:daemon:stop',
:before_start => method(:before_start),
:ping_command => lambda { TCPSocket.new(Ultrasphinx::CLIENT_SETTINGS['server_host'], Ultrasphinx::CLIENT_SETTINGS['server_port']) },
:pid_file => Ultrasphinx::DAEMON_SETTINGS['pid_file'],
:log_file => Ultrasphinx::DAEMON_SETTINGS["log"])
end
def method_missing(method, *args, &block)
@controller.respond_to?(method) ? @controller.send(method, *args, &block) : super
end
def respond_to?(method)
super || @controller.respond_to?(method)
end
private
def before_start
`rake ultrasphinx:configure ultrasphinx:index`
end
end
Ultrasphinx::Search::Internals.send(:include, UltrasphinxInternalsMonkeyPatch)
module UltrasphinxInternalsMonkeyPatch
def self.included(receiver)
receiver.class_eval do
alias_method_chain :perform_action_with_retries, :autostart
end
end
def perform_action_with_retries_with_autostart(&block)
@server ||= SearchServer.new
@server.start unless @server.running?
perform_action_with_retries_without_autostart(&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment