Created
October 7, 2008 20:29
-
-
Save jamesgolick/15370 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ultrasphinx::Search::Internals.send(:include, UltrasphinxInternalsMonkeyPatch) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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