How to make my sinatra script process requests simultaneously?

88 views
Skip to first unread message

cimenta

unread,
Dec 21, 2011, 11:20:16 PM12/21/11
to sinatrarb
hi

I have one simple sinatra script

require 'rubygems'
require 'sinatra'

get '/' do
output=%x[sleep.bat] #dos batch file that waits for 10sec
output
end

get '/getresults' do
puts "get results"
end

which simulates my real sintra script that calls ant scripts (web
testing using IBM Rational Functional Tester). Only one ant script can
be running at a time. The ant script can finish in hours or so. I want
to use my sinatra application while the ant run is running. But
sinatra waits till the ant script finishes. Then it processes whatever
requests I made meanwhile.

My configuration:

- Windows XP SP3
- ruby 1.8.7 (2010-08-16 patchlevel 302) [i386-mingw32]
- sinatra (1.2.6, 1.0)
- and one rb file

Is there any sinatra only solution or something that wouldn't be much
memory and cpu costly?

Thank you

Radek


Joel VanderWerf

unread,
Dec 22, 2011, 12:55:13 PM12/22/11
to sina...@googlegroups.com
On 12/21/2011 08:20 PM, cimenta wrote:
> hi
>
> I have one simple sinatra script
>
> require 'rubygems'
> require 'sinatra'
>
> get '/' do
> output=%x[sleep.bat] #dos batch file that waits for 10sec
> output
> end
>
> get '/getresults' do
> puts "get results"
> end
>
> which simulates my real sintra script that calls ant scripts (web
> testing using IBM Rational Functional Tester). Only one ant script can
> be running at a time. The ant script can finish in hours or so. I want
> to use my sinatra application while the ant run is running. But
> sinatra waits till the ant script finishes. Then it processes whatever
> requests I made meanwhile.

The stream feature is not working perfectly yet, but it allows you to do
this:

get "/" do
stream do |out|
out << %x[sleep.bat]
end
end

If you're running sinatra on top of thin, this construct will use a
thread to wait for the external process, so your other requests will
still be handled.

cimenta

unread,
Jan 2, 2012, 8:49:53 PM1/2/12
to sinatrarb
It's like it doesn't run %x[sleep.bat] It always returns an empty
array. Instantly.

get '/' do
output = Array.new stream do |output|   output << %x[sleep.bat]  
end
output.inspect #gives instalnly []
end

sinatra (1.3.2)
sinatra-advanced-routes (0.5.1)
sinatra-reloader (0.5.0)
sinatra-sugar (0.5.1)

Thank you

Radek
On Dec 23 2011, 4:55 am, Joel VanderWerf <joelvanderw...@gmail.com>
wrote:

cimenta

unread,
Jan 2, 2012, 10:56:04 PM1/2/12
to sinatrarb
hm, not sure if it was just sinatra upgrade but now without any code
change sinatra behaves simultaneously ... :-)

Thank you

Radek
Reply all
Reply to author
Forward
0 new messages