I coded small web app that runs ant (batch file). The processing time of the batch file could take up to minutes.
index.haml list all available ant files and run.haml runs them. The flow how it works now is that when I click a link from index.haml the ant script is run and after it finishes the whole run.haml page is sent to the browser. So after clicking link from index.haml I still can see index.haml and nothing from run.haml
After I click a link from index.haml I want to
- show what script is going to be run and then
- run the ant script and then
- display the results of it.
I was recommended in my other question to use
- an Ajax call or
- a separate worker thread. Like BackgrounDRb, run_later or delayed_job
I didn't understand how a separate worker thread could help me. Would the delayed job's results that are captured by ruby's call be sent to the browser once the job finishes?
I also didn't get how I can use Ajax in sinatra.
Could somebody point me out what a solution for that could be like? Please note that I know bit of ruby, learned bit of sinatra and haml yesterday. No nothing about Ajax :-) I learn by examples ... and happy to learn anything.
index.haml gives me html like
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Available test suits</title>
</head>
<body>
<h1>Available test suits</h1>
<br/><br/>
<a href='run?run=login_build'>login_build</a>
<br />
<a href='run?run=login_cycle_build'>login_cycle_build</a>
<br />
<a href='run?run=login_cycle_academicyear_build'>login_cycle_academicyear_build</a>
</body>
</html>
run.haml looks like
!!!
%html
%head
%title Running
%body
= "Starting test suite: #{params['run']}"
- output = %x[cd C:\\Program Files\\TestPro\\TestPro Automation Framework410 && ant -lib lib -f "C:\\Program Files\\TestPro\\TestPro Automation Framework410\\Output Files\\builds\\#{params['run']}.xml"]
-#The result is
%br
= output.split("\n")[-2,2].join("<BR>")
= "<br/>"*2
%a(href="/")back to suits list