Forum: Ruby on Rails Newbie question about periodically_call_remote

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Nate D. (Guest)
on 2006-01-18 03:41

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:
(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?


Will B. (Guest)
on 2006-01-18 03:48
(Received via mailing list)
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?

Nate D. (Guest)
on 2006-01-19 16:59
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.



==== 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


    render :partial => 'status'

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

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

    session["building"] = 0


  def printStatus
      render :text => session["build_status"]

==== index.rhtml:
  <%= javascript_include_tag :defaults %>

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

  <div id="update">

  <div id="status">


==== _status.rhtml:
    <%= periodically_call_remote(
	    :update => "status",
            :url => {:action => "printStatus"}) if session["building"]
== 1 %>
This topic is locked and can not be replied to.