Newbie question about periodically_call_remote

Hi,

I’m new to Ruby on Rails (and Ruby itself). So far, I’ve been able to
find answers to most of my questions in the docs or mailing lists. One
thing I haven’t been able to find the answer to is how to stop a
periodically_call_remote call. My first Rails app is going to be a
front-end for our Ant-based build system at work. While the build is
running, I’d like to give the user status info. To do this, I’m using a
scheme I found here:
http://rails.techno-weenie.net/question/2005/12/24/how_do_you_display_the_progress_of_a_long_running_action
(See post 5). The problem is, after the build has completed, I’d like
to stop the periodically_call_remote from executing. What is the best
way to do this?

Thanks!

Nate

Well, (I think) one way to do it would be to have the
periodically_call_remote call in the HTML fragment that is being
refreshed. In that fragment, check to see if the build is complete,
and if so, omit the call to periodically_call_remote.

I’m a Rails noob and have not done this myself, but I can’t see any
reason why this wouldn’t work. Maybe someone with more AJAX
experience can come up with something better?

-Will

Thanks for the reply, Will! I’ve also run into another issue. In the
build method of my controller, I do a IO.popen() to execute ant and
build our app. Even though I’m using link_to_remote to call the build
action, it seems to block the periodically_call_remote I render to the
client. Should this work or am I going about this whole thing the wrong
way? Would it be better to use drb and have my build action talk to a
remote app which actually runs the builds?

Below is the code I have now. Any tips would be greatly appreciated.

Thanks!!

Nate

==== builder_controller.rb:

def build
# Session var containing status message to show user
session[“build_status”] = “Starting build…”

# Session var used to indicate if a build is running
session["building"] = 1

session.update

render :partial => 'status'

IO.popen("cd /tmp && sleep 60")  # This will execute ant
Process.wait

if ($? >> 8) == 0 then
  session["build_status"] = "Built ok"
  session.update
else
  session["build_status"] = "Build failed."
  session.update
end

session["building"] = 0
session.update

end

def printStatus
render :text => session[“build_status”]
end

==== index.rhtml:

Builder <%= javascript_include_tag :defaults %>

<%= link_to_remote( “click here”,
:update => “update”,
:url =>{ :action => “build” }) %>

==== _status.rhtml:

<%= periodically_call_remote( :update => "status", :url => {:action => "printStatus"}) if session["building"] == 1 %>