Created
October 9, 2012 19:17
-
-
Save mguterl/3860830 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 "net/http" | |
module Blocking | |
module Sunspot | |
class Server < ::Sunspot::Rails::Server | |
def start | |
@started = Time.now | |
super | |
up | |
rescue ::Sunspot::Server::AlreadyRunningError | |
# do nothing | |
end | |
private | |
def uri | |
"http://0.0.0.0:#{port}/solr/" | |
end | |
def up | |
while starting | |
puts "Sunspot server is starting..." | |
end | |
puts "Sunspot server took #{'%.2f' % (Time.now - @started)} sec. to get up and running." | |
end | |
def starting | |
begin | |
sleep(1) | |
request = Net::HTTP.get_response(URI.parse(uri)) | |
false | |
rescue Errno::ECONNREFUSED | |
true | |
end | |
end | |
end # Server | |
end # Sunspot | |
end # Blocking | |
Blocking::Sunspot::Server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment