tags:

views:

29

answers:

1

I have a run.haml file where I run a test suit. Everything works just fine but I want to display the text "Starting test suite: #{params['run']}" immediately after user clicks the link that leads him to this haml.

the link clicked tells haml what suit needs to be executed

%a(href="run?run=#{file}")

Right now everything is displayed after the test suit run finishes. The run.haml page is being loaded till the script finishes.

  • how does the haml processing flow work?
  • can I start processing the job after the page starts rendering?
  • can I display some text in a browser and then let call the test suit?

It takes minutes to finish the run of the test suit.


    !!!  
    %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
+1  A: 

Well, look -- my thought here is that it's not rendering everything (for whatever reason) until that function call returns.

If that's the case, you'll want to process the result of that function separately from loading the test harness page -- so, you'll want to invoke the test suite either with

That choice depends on the length of time the function (generally) takes to run -- so, depending on the complexity, it may be a good candidate for something like BackgrounDRb, run_later or delayed_job, or even a custom daemon.

Finally, you may find this example of using Sinatra with delayed_job helpful.

Joe
@Joe: well, actually I am writing kind of daemon right now. I am happy if at least the page title is displayed. But as you say it is not rendering anything until that function call finishes.
Radek
Maybe we could clarify the question -- the problem probably isn't Haml. After all, a .haml page shouldn't process this sort of thing any differently from a vanilla .erb page. The same thing would happen. So the question now is how to re-engineer the page to invoke the test suite ONLY once the page is loaded -- or am I missing something?
Joe
can I run separate worker thread from haml? could you give me any url about using separate worker thread in ruby?
Radek
you're right. I want to start processing the job after the page starts rendering.
Radek
Yes! You can definitely run separate worker threads in Rails. This is common and even a best practice for long-running tasks. Webservers tend to block until the request is fulfilled, so popping a long-running task in the middle of your page will make loading your site crawl.
Joe
You probably want to use BackgrounDRb. It's designed for this, simple to use and well-integrated with Rails: http://backgroundrb.rubyforge.org/rails/
Joe
I am not using Rails.I just learned on the fly bit if Sinatra and haml yesterday. It does what I want but I wanted to improve user's experience little bit.
Radek
so now the question is if I can use BackgrounDRb from haml
Radek
Don't worry, BackgrounDRb and delayed_job aren't tied to Rails -- it will still let you do what you're trying to do. An example of using Sinatra with delayed_job can be found here: http://github.com/bmizerany/sinatra-dj
Joe
you're a legend! let me do some reading
Radek
@Joe: not sure how I can make this work. I need to use DJ in my ruby/Sinatra code or haml? do ruby and haml share objects? I cannot see how I can display the web page and then once the job finishes I can process its results...
Radek
The problem now is about passing data back from a worker thread. It's all in Ruby; Haml is just a template for generating HTML. Study the example carefully. Modify it to run your tests (instead of translating from Pig Latin.) If you are still running into roadblocks, try posting a new question. Or ask here :)
Joe