mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Improve server
This commit is contained in:
parent
351d5f2cf9
commit
00b75d8495
2 changed files with 21 additions and 18 deletions
|
@ -8,7 +8,8 @@ module Webcat
|
||||||
attr_accessor :debug
|
attr_accessor :debug
|
||||||
|
|
||||||
def log(message)
|
def log(message)
|
||||||
puts message if debug
|
puts "[webcat] #{message}" if debug
|
||||||
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Webcat::Server
|
||||||
end
|
end
|
||||||
|
|
||||||
def port
|
def port
|
||||||
9081
|
8080
|
||||||
end
|
end
|
||||||
|
|
||||||
def host
|
def host
|
||||||
|
@ -21,25 +21,17 @@ class Webcat::Server
|
||||||
end
|
end
|
||||||
|
|
||||||
def boot
|
def boot
|
||||||
Webcat.log "[webcat] Booting Rack applicartion on port #{port}"
|
Webcat.log "application has already booted" and return if responsive?
|
||||||
|
Webcat.log "booting Rack applicartion on port #{port}"
|
||||||
start_time = Time.now
|
start_time = Time.now
|
||||||
Thread.new do
|
Thread.new do
|
||||||
Rack::Handler::Mongrel.run @app, :Port => port
|
Rack::Handler::Mongrel.run @app, :Port => port
|
||||||
end
|
end
|
||||||
Webcat.log "[webcat] checking if application has booted"
|
Webcat.log "checking if application has booted"
|
||||||
loop do
|
loop do
|
||||||
begin
|
Webcat.log("application has booted") and break if responsive?
|
||||||
res = Net::HTTP.start(host, port) { |http| http.get('/') }
|
if Time.now - start_time > 10
|
||||||
|
Webcat.log "Rack application timed out during boot"
|
||||||
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
|
||||||
Webcat.log "[webcat] application has booted"
|
|
||||||
break
|
|
||||||
end
|
|
||||||
rescue Errno::ECONNREFUSED
|
|
||||||
end
|
|
||||||
|
|
||||||
if Time.now - start_time > 5
|
|
||||||
puts "[webcat] Rack application timed out during boot"
|
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,4 +40,14 @@ class Webcat::Server
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def responsive?
|
||||||
|
res = Net::HTTP.start(host, port) { |http| http.get('/') }
|
||||||
|
|
||||||
|
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
rescue Errno::ECONNREFUSED
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in a new issue