lib/http/broker.rb in rsence-2.0.0.3.pre vs lib/http/broker.rb in rsence-2.0.0.4.pre

- old
+ new

@@ -28,10 +28,21 @@ =end class Broker def call(env) + sleep @@ping_sim if @@ping_sim + unless @@transporter.online? + puts "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} -- Server busy." + headers = { + 'Retry-After' => '2', + 'Content-Type' => 'text/plain', + 'Refresh' => "2; #{env['REQUEST_URI']}", + 'Content-Length' => '4' + } + return [ 503, headers, 'BUSY' ] + end request = Request.new(env) response = Response.new request_method = request.request_method.downcase dispatcher = dispatcher_class.new( request, response ) dispatcher.send(request_method) @@ -56,10 +67,17 @@ if conf == 0 @@ping_sim = false else @@ping_sim = conf/1000.0 end + Thread.new do + Thread.pass + until RSence.argv.test_port( port, host ) + sleep 0.1 + end + @@transporter.online = true + end handler.run( Rack::Lint.new(self.new), :Host => host, :Port => port ) end def self.included(receiver) receiver.extend( SingletonMethods ) @@ -77,21 +95,17 @@ ## Post requests are always xhr requests def post puts "post: #{@request.fullpath}" if RSence.args[:verbose] - sleep @@ping_sim if @@ping_sim - not_found unless @@transporter.servlet( :post, @request, @response ) end ## Get requests are different, depending on the uri requested def get puts "get: #{@request.fullpath}" if RSence.args[:verbose] - - sleep @@ping_sim if @@ping_sim not_found unless @@transporter.servlet( :get, @request, @response ) end