Forum: Ruby on Rails Newbie question about periodically_call_remote

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Da928ce3c7edebf59a461977e74c7919?d=identicon&s=25 Nate Drake (ndrake)
on 2006-01-18 02:41
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...
(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
9b7647d55df4584d7031130915556040?d=identicon&s=25 Will Briggs (Guest)
on 2006-01-18 02: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?

-Will
Da928ce3c7edebf59a461977e74c7919?d=identicon&s=25 Nate Drake (ndrake)
on 2006-01-19 15: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.

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:
<html>
<head>
  <title>Builder</title>
  <%= javascript_include_tag :defaults %>
</head>
<body>

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

  <div id="update">
  </div>

  <div id="status">
  </div>

</body>
</html>


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